get_order_book
Retrieve all orders placed during the day with their current status. This tool provides real-time order tracking and management for DhanHQ trading operations.
Instructions
Retrieves all orders placed during the day with their current status. Requires authentication.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:572-583 (handler)MCP tool handler case that executes get_order_book by calling the getOrderBook helper function and returns the orders as JSON text content.case 'get_order_book': { console.error('[Tool] Executing: get_order_book'); const orders = await getOrderBook(); return { content: [ { type: 'text' as const, text: JSON.stringify(orders, null, 2), }, ], }; }
- src/authentication.ts:350-373 (helper)Core helper function that performs the actual API call to retrieve the order book from Dhan API using axios GET request with authentication headers.export async function getOrderBook(): Promise<OrderBook[]> { try { log('Fetching order book...'); const response = await axios.get<OrderBook[]>( 'https://api.dhan.co/v2/orders', { headers: getApiHeaders(), } ); log(`✓ Order book retrieved. Total orders: ${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 book: ${errorMessage}`); throw new Error(`Failed to get order book: ${errorMessage}`); }
- src/index.ts:200-209 (registration)Tool registration object in the tools array used by ListToolsRequestHandler, defining name, description, and empty input schema.{ name: 'get_order_book', description: 'Retrieves all orders placed during the day with their current status. Requires authentication.', inputSchema: { type: 'object' as const, properties: {}, required: [], }, },
- src/types.ts:80-100 (schema)TypeScript interface defining the structure of OrderBook objects returned by the getOrderBook function.export interface OrderBook { dhanClientId: string; orderId: string; correlationId: string; orderStatus: string; transactionType: string; exchangeSegment: string; productType: string; orderType: string; validity: string; securityId: string; quantity: number; price: number; triggerPrice?: number; disclosedQuantity?: number; createTime: string; algoId?: string; remainingQuantity: number; filledQty: number; updateTime?: string; }