get_order_trades
Retrieve all trade executions for a specific order to track partial fills or bracket/cover order outcomes. Requires authentication with DhanHQ trading APIs.
Instructions
Retrieves all trades for a specific order. Useful for partial fills or bracket/cover orders. Requires authentication.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orderId | Yes | Order ID to get trades for |
Input Schema (JSON Schema)
{
"properties": {
"orderId": {
"description": "Order ID to get trades for",
"type": "string"
}
},
"required": [
"orderId"
],
"type": "object"
}
Implementation Reference
- src/authentication.ts:470-494 (handler)The core handler function that executes the get_order_trades tool logic by fetching trades for the given orderId from the Dhan API endpoint and returning TradeBook[]export async function getOrderTrades(orderId: string): Promise<TradeBook[]> { try { log(`Fetching trades for order: ${orderId}`); const response = await axios.get<TradeBook[]>( `https://api.dhan.co/v2/trades/${orderId}`, { headers: getApiHeaders(), } ); log(`✓ Trades retrieved. Total trades: ${response.data.length}`); return response.data; } catch (error) { const errorMessage = error instanceof axios.AxiosError ? `API Error: ${error.response?.status} - ${JSON.stringify(error.response?.data)}` : error instanceof Error ? error.message : 'Unknown error'; log(`✗ Failed to get order trades: ${errorMessage}`); throw new Error(`Failed to get order trades: ${errorMessage}`); } }
- src/index.ts:244-255 (schema)Input schema and metadata for the 'get_order_trades' tool, defining the required 'orderId' parameter.{ name: 'get_order_trades', description: 'Retrieves all trades for a specific order. Useful for partial fills or bracket/cover orders. Requires authentication.', inputSchema: { type: 'object' as const, properties: { orderId: { type: 'string', description: 'Order ID to get trades for' }, }, required: ['orderId'], }, },
- src/index.ts:626-638 (registration)Registration and dispatch logic in the main tool handler switch statement that matches the tool name, extracts arguments, calls the getOrderTrades function, and returns the formatted response.case 'get_order_trades': { console.error('[Tool] Executing: get_order_trades'); const { orderId } = args as Record<string, unknown>; const trades = await getOrderTrades(orderId as string); return { content: [ { type: 'text' as const, text: JSON.stringify(trades, null, 2), }, ], }; }
- src/types.ts:102-113 (schema)TypeScript interface defining the structure of a TradeBook object, used as the return type for getOrderTrades.export interface TradeBook { dhanClientId: string; orderId: string; exchangeOrderId: string; exchangeTradeId: string; transactionType: string; exchangeSegment: string; tradingSymbol: string; tradedQuantity: number; tradedPrice: number; exchangeTime: string; }
- src/index.ts:22-22 (registration)Import of the getOrderTrades handler function from authentication module.getOrderTrades,