cancel_order
Cancel a specific trading order on Binance exchange by providing the trading pair symbol and order ID to manage open positions effectively.
Instructions
取消指定订单 - 支持主网和测试网
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orderId | Yes | 订单ID | |
| symbol | Yes | 交易对符号,如 BTCUSDT |
Implementation Reference
- src/tools/trading.ts:124-156 (handler)The handler function that executes the cancel_order tool logic: validates input using CancelOrderSchema, calls binanceClient.cancelOrder, and returns the result.handler: async (binanceClient: any, args: unknown) => { const networkMode = validateAndWarnMainnet(); const input = validateInput(CancelOrderSchema, args); validateSymbol(input.symbol); try { const cancelResult = await binanceClient.cancelOrder({ symbol: input.symbol, orderId: input.orderId, }); return { symbol: cancelResult.symbol, origClientOrderId: cancelResult.origClientOrderId, orderId: cancelResult.orderId, orderListId: cancelResult.orderListId, clientOrderId: cancelResult.clientOrderId, price: cancelResult.price, origQty: cancelResult.origQty, executedQty: cancelResult.executedQty, cummulativeQuoteQty: cancelResult.cummulativeQuoteQty, status: cancelResult.status, timeInForce: cancelResult.timeInForce, type: cancelResult.type, side: cancelResult.side, timestamp: Date.now(), network: networkMode, }; } catch (error) { handleBinanceError(error); } },
- src/tools/trading.ts:107-157 (registration)The cancel_order tool definition within the tradingTools array, including name, description, inputSchema, and handler reference. This array is exported and used for registration.{ name: 'cancel_order', description: '取消指定订单 - 支持主网和测试网', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: '交易对符号,如 BTCUSDT', }, orderId: { type: 'number', description: '订单ID', }, }, required: ['symbol', 'orderId'], }, handler: async (binanceClient: any, args: unknown) => { const networkMode = validateAndWarnMainnet(); const input = validateInput(CancelOrderSchema, args); validateSymbol(input.symbol); try { const cancelResult = await binanceClient.cancelOrder({ symbol: input.symbol, orderId: input.orderId, }); return { symbol: cancelResult.symbol, origClientOrderId: cancelResult.origClientOrderId, orderId: cancelResult.orderId, orderListId: cancelResult.orderListId, clientOrderId: cancelResult.clientOrderId, price: cancelResult.price, origQty: cancelResult.origQty, executedQty: cancelResult.executedQty, cummulativeQuoteQty: cancelResult.cummulativeQuoteQty, status: cancelResult.status, timeInForce: cancelResult.timeInForce, type: cancelResult.type, side: cancelResult.side, timestamp: Date.now(), network: networkMode, }; } catch (error) { handleBinanceError(error); } }, },
- src/types/mcp.ts:41-44 (schema)Zod schema (CancelOrderSchema) used for input validation in the cancel_order handler.export const CancelOrderSchema = z.object({ symbol: z.string().describe('交易对符号'), orderId: z.number().describe('订单ID'), });
- src/server.ts:41-50 (registration)Registers all tools, including those from tradingTools (containing cancel_order), into the server's tools Map by name.private setupTools(): void { const allTools = [ ...marketDataTools, ...accountTools, ...tradingTools, ]; for (const tool of allTools) { this.tools.set(tool.name, tool); }
- src/types/binance.ts:116-130 (schema)TypeScript interface for the Binance cancel order response, used in handler return type.export interface BinanceCancelOrderResponse { symbol: string; origClientOrderId: string; orderId: number; orderListId: number; clientOrderId: string; price: string; origQty: string; executedQty: string; cummulativeQuoteQty: string; status: OrderStatus; timeInForce: TimeInForce; type: OrderType; side: OrderSide; }