modify_order
Update pending trading orders by changing price, quantity, order type, or other parameters through the DhanHQ trading platform.
Instructions
Modifies a pending order. Can change price, quantity, order type, and other parameters. Requires authentication.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orderId | Yes | Order ID to modify | |
| dhanClientId | Yes | Your Dhan client ID | |
| orderType | Yes | ||
| quantity | No | New quantity | |
| price | No | New price (for LIMIT/STOP_LOSS) | |
| triggerPrice | No | New trigger price (for STOP_LOSS/STOP_LOSS_MARKET) | |
| disclosedQuantity | No | New disclosed quantity |
Input Schema (JSON Schema)
{
"properties": {
"dhanClientId": {
"description": "Your Dhan client ID",
"type": "string"
},
"disclosedQuantity": {
"description": "New disclosed quantity",
"type": "number"
},
"orderId": {
"description": "Order ID to modify",
"type": "string"
},
"orderType": {
"enum": [
"MARKET",
"LIMIT",
"STOP_LOSS",
"STOP_LOSS_MARKET"
],
"type": "string"
},
"price": {
"description": "New price (for LIMIT/STOP_LOSS)",
"type": "number"
},
"quantity": {
"description": "New quantity",
"type": "number"
},
"triggerPrice": {
"description": "New trigger price (for STOP_LOSS/STOP_LOSS_MARKET)",
"type": "number"
}
},
"required": [
"orderId",
"dhanClientId",
"orderType"
],
"type": "object"
}
Implementation Reference
- src/authentication.ts:288-316 (handler)Core handler function that executes the HTTP PUT request to the Dhan API to modify a pending order.export async function modifyOrder( orderId: string, request: ModifyOrderRequest ): Promise<OrderResponse> { try { log(`Modifying order: ${orderId}`); const response = await axios.put<OrderResponse>( `https://api.dhan.co/v2/orders/${orderId}`, request, { headers: getApiHeaders(), } ); log(`✓ Order modified successfully. Order ID: ${response.data.orderId}`); 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 modify order: ${errorMessage}`); throw new Error(`Failed to modify order: ${errorMessage}`); } }
- src/index.ts:167-187 (registration)MCP tool registration defining the 'modify_order' tool name, description, and input schema.{ name: 'modify_order', description: 'Modifies a pending order. Can change price, quantity, order type, and other parameters. Requires authentication.', inputSchema: { type: 'object' as const, properties: { orderId: { type: 'string', description: 'Order ID to modify' }, dhanClientId: { type: 'string', description: 'Your Dhan client ID' }, orderType: { type: 'string', enum: ['MARKET', 'LIMIT', 'STOP_LOSS', 'STOP_LOSS_MARKET'], }, quantity: { type: 'number', description: 'New quantity' }, price: { type: 'number', description: 'New price (for LIMIT/STOP_LOSS)' }, triggerPrice: { type: 'number', description: 'New trigger price (for STOP_LOSS/STOP_LOSS_MARKET)' }, disclosedQuantity: { type: 'number', description: 'New disclosed quantity' }, }, required: ['orderId', 'dhanClientId', 'orderType'], }, },
- src/types.ts:115-123 (schema)TypeScript interface defining the structure of the ModifyOrderRequest used by the handler.export interface ModifyOrderRequest { dhanClientId: string; orderId: string; orderType: 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_MARKET'; quantity?: number; price?: number; triggerPrice?: number; disclosedQuantity?: number; }
- src/index.ts:536-556 (handler)MCP server request handler that processes 'modify_order' tool calls and delegates to the core modifyOrder function.case 'modify_order': { console.error('[Tool] Executing: modify_order'); const modifyArgs = args as Record<string, unknown>; const result = await modifyOrder(modifyArgs.orderId as string, { dhanClientId: modifyArgs.dhanClientId as string, orderId: modifyArgs.orderId as string, orderType: modifyArgs.orderType as 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_MARKET', quantity: modifyArgs.quantity as number | undefined, price: modifyArgs.price as number | undefined, triggerPrice: modifyArgs.triggerPrice as number | undefined, disclosedQuantity: modifyArgs.disclosedQuantity as number | undefined, }); return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2), }, ], }; }