get_trade_book
Retrieve all trades executed during the day to track fills and execution prices. Requires authentication with DhanHQ trading APIs.
Instructions
Retrieves all trades executed during the day. Useful for tracking fills and execution prices. Requires authentication.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/authentication.ts:441-465 (handler)Core handler function that executes the tool logic by fetching the day's trade book from the Dhan API endpoint 'https://api.dhan.co/v2/trades' using the authenticated access token.export async function getTradeBook(): Promise<TradeBook[]> { try { log('Fetching trade book...'); const response = await axios.get<TradeBook[]>( 'https://api.dhan.co/v2/trades', { headers: getApiHeaders(), } ); log(`✓ Trade book 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 trade book: ${errorMessage}`); throw new Error(`Failed to get trade book: ${errorMessage}`); } }
- src/index.ts:234-243 (schema)Tool schema definition including name, description, and empty input schema (no parameters required). Output is implicitly TradeBook[].{ name: 'get_trade_book', description: 'Retrieves all trades executed during the day. Useful for tracking fills and execution prices. Requires authentication.', inputSchema: { type: 'object' as const, properties: {}, required: [], }, },
- src/index.ts:613-624 (registration)MCP callTool request handler (switch case) that registers and dispatches the 'get_trade_book' tool call to the getTradeBook function and formats the response.case 'get_trade_book': { console.error('[Tool] Executing: get_trade_book'); const trades = await getTradeBook(); return { content: [ { type: 'text' as const, text: JSON.stringify(trades, null, 2), }, ], }; }