Skip to main content
Glama
ethancod1ng

Binance MCP Server

by ethancod1ng

cancel_all_orders

Cancel all open orders for a specific trading pair on Binance exchange to manage positions and reduce exposure.

Instructions

取消指定交易对所有挂单 - 支持主网和测试网

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes交易对符号,如 BTCUSDT

Implementation Reference

  • The handler function that executes the cancel_all_orders tool: validates input, calls binanceClient.cancelOpenOrders(symbol), processes results into cancelledOrders array, and returns formatted response including count and network mode.
    handler: async (binanceClient: any, args: unknown) => {
      const networkMode = validateAndWarnMainnet();
      
      const input = validateInput(CancelAllOrdersSchema, args);
      validateSymbol(input.symbol);
    
      try {
        const cancelResults = await binanceClient.cancelOpenOrders({
          symbol: input.symbol,
        });
    
        return {
          symbol: input.symbol,
          cancelledOrders: Array.isArray(cancelResults) ? cancelResults.map((result: any) => ({
            symbol: result.symbol,
            origClientOrderId: result.origClientOrderId,
            orderId: result.orderId,
            orderListId: result.orderListId,
            clientOrderId: result.clientOrderId,
            price: result.price,
            origQty: result.origQty,
            executedQty: result.executedQty,
            cummulativeQuoteQty: result.cummulativeQuoteQty,
            status: result.status,
            timeInForce: result.timeInForce,
            type: result.type,
            side: result.side,
          })) : [cancelResults],
          count: Array.isArray(cancelResults) ? cancelResults.length : 1,
          timestamp: Date.now(),
          network: networkMode,
        };
      } catch (error) {
        handleBinanceError(error);
      }
    },
  • Tool registration as part of the tradingTools export array, defining name, description, inputSchema for MCP, and handler reference.
    {
      name: 'cancel_all_orders',
      description: '取消指定交易对所有挂单 - 支持主网和测试网',
      inputSchema: {
        type: 'object',
        properties: {
          symbol: {
            type: 'string',
            description: '交易对符号,如 BTCUSDT',
          },
        },
        required: ['symbol'],
      },
      handler: async (binanceClient: any, args: unknown) => {
        const networkMode = validateAndWarnMainnet();
        
        const input = validateInput(CancelAllOrdersSchema, args);
        validateSymbol(input.symbol);
    
        try {
          const cancelResults = await binanceClient.cancelOpenOrders({
            symbol: input.symbol,
          });
    
          return {
            symbol: input.symbol,
            cancelledOrders: Array.isArray(cancelResults) ? cancelResults.map((result: any) => ({
              symbol: result.symbol,
              origClientOrderId: result.origClientOrderId,
              orderId: result.orderId,
              orderListId: result.orderListId,
              clientOrderId: result.clientOrderId,
              price: result.price,
              origQty: result.origQty,
              executedQty: result.executedQty,
              cummulativeQuoteQty: result.cummulativeQuoteQty,
              status: result.status,
              timeInForce: result.timeInForce,
              type: result.type,
              side: result.side,
            })) : [cancelResults],
            count: Array.isArray(cancelResults) ? cancelResults.length : 1,
            timestamp: Date.now(),
            network: networkMode,
          };
        } catch (error) {
          handleBinanceError(error);
        }
      },
    },
  • Zod schema used for input validation in the handler: requires 'symbol' as string.
    export const CancelAllOrdersSchema = z.object({
      symbol: z.string().describe('交易对符号'),
    });
  • src/server.ts:41-51 (registration)
    Server setup where tradingTools (including cancel_all_orders) are spread into allTools and registered into the MCP 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 type inferred from CancelAllOrdersSchema for input typing.
    export type CancelAllOrdersInput = z.infer<typeof CancelAllOrdersSchema>;

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