Skip to main content
Glama
ethancod1ng

Binance MCP Server

by ethancod1ng

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
NameRequiredDescriptionDefault
orderIdYes订单ID
symbolYes交易对符号,如 BTCUSDT

Implementation Reference

  • 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);
      }
    },
  • 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);
        }
      },
    },
  • 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);
      }
  • 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;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ethancod1ng/binance-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server