Skip to main content
Glama

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

NameRequiredDescriptionDefault
orderIdYesOrder 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

  • 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}`); } }
  • 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), }, ], }; }
  • 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,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/harshitdynamite/DhanMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server