cancelOrder
Cancel open trading orders on Bitget exchange by specifying order ID and trading pair symbol. This tool manages active positions in cryptocurrency spot and futures markets.
Instructions
Cancel an existing order
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orderId | Yes | Order ID to cancel | |
| symbol | Yes | Trading pair symbol |
Implementation Reference
- src/server.ts:400-411 (handler)MCP server handler for the 'cancelOrder' tool. Parses input arguments using CancelOrderSchema, calls the BitgetRestClient.cancelOrder method, and returns a success or failure message.case 'cancelOrder': { const { orderId, symbol } = CancelOrderSchema.parse(args); const success = await this.bitgetClient.cancelOrder(orderId, symbol); return { content: [ { type: 'text', text: success ? `Order ${orderId} cancelled successfully` : `Failed to cancel order ${orderId}`, }, ], } as CallToolResult; }
- src/types/mcp.ts:51-54 (schema)Zod schema defining the input parameters for the cancelOrder tool: orderId and symbol.export const CancelOrderSchema = z.object({ orderId: z.string().describe('Order ID to cancel'), symbol: z.string().describe('Trading pair symbol') });
- src/server.ts:182-192 (registration)Registration of the 'cancelOrder' tool in the MCP server's listTools response, including name, description, and input schema matching the Zod schema.name: 'cancelOrder', description: 'Cancel an existing order', inputSchema: { type: 'object', properties: { orderId: { type: 'string', description: 'Order ID to cancel' }, symbol: { type: 'string', description: 'Trading pair symbol' } }, required: ['orderId', 'symbol'] }, },
- src/api/rest-client.ts:650-685 (helper)Core implementation of cancelOrder in BitgetRestClient. Determines if spot or futures based on symbol, then calls the appropriate private cancel method using Bitget API endpoints.async cancelOrder(orderId: string, symbol: string): Promise<boolean> { if (this.isFuturesSymbol(symbol)) { return this.cancelFuturesOrder(orderId, symbol); } else { return this.cancelSpotOrder(orderId, symbol); } } /** * Cancel a spot order */ private async cancelSpotOrder(orderId: string, symbol: string): Promise<boolean> { const response = await this.request<any>('POST', '/api/v2/spot/trade/cancel-order', { orderId, symbol }, true); return response.code === '00000'; } /** * Cancel a futures order */ private async cancelFuturesOrder(orderId: string, symbol: string): Promise<boolean> { // Remove _UMCBL suffix for v1 API const cleanSymbol = symbol.replace('_UMCBL', ''); const response = await this.request<any>('POST', '/api/v2/mix/order/cancel-order', { orderId, symbol: cleanSymbol, productType: 'USDT-FUTURES', marginCoin: 'USDT' }, true); return response.code === '00000'; }