Skip to main content
Glama
ethancod1ng

Binance MCP Server

by ethancod1ng

get_open_orders

Retrieve current open orders from Binance exchange to monitor pending trades and manage active positions efficiently.

Instructions

获取当前挂单

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolNo特定交易对的挂单,不传则获取所有挂单

Implementation Reference

  • The main handler function for the 'get_open_orders' tool. Validates input using GetOpenOrdersSchema, fetches open orders via binanceClient.openOrders, maps the response, and handles errors.
    handler: async (binanceClient: any, args: unknown) => {
      const input = validateInput(GetOpenOrdersSchema, args);
      
      if (input.symbol) {
        validateSymbol(input.symbol);
      }
    
      try {
        const openOrders = await binanceClient.openOrders(
          input.symbol ? { symbol: input.symbol } : {}
        );
    
        return {
          symbol: input.symbol || 'ALL',
          orders: openOrders.map((order: any) => ({
            symbol: order.symbol,
            orderId: order.orderId,
            orderListId: order.orderListId,
            clientOrderId: order.clientOrderId,
            price: order.price,
            origQty: order.origQty,
            executedQty: order.executedQty,
            cummulativeQuoteQty: order.cummulativeQuoteQty,
            status: order.status,
            timeInForce: order.timeInForce,
            type: order.type,
            side: order.side,
            stopPrice: order.stopPrice,
            icebergQty: order.icebergQty,
            time: order.time,
            updateTime: order.updateTime,
            isWorking: order.isWorking,
            origQuoteOrderQty: order.origQuoteOrderQty,
          })),
          count: openOrders.length,
          timestamp: Date.now(),
        };
      } catch (error) {
        handleBinanceError(error);
      }
    },
  • Zod schema defining the input for get_open_orders: optional symbol parameter.
    export const GetOpenOrdersSchema = z.object({
      symbol: z.string().optional().describe('特定交易对的挂单'),
    });
  • Tool registration object defining name, description, inputSchema (JSON Schema), and handler for 'get_open_orders' within the accountTools array.
    {
      name: 'get_open_orders',
      description: '获取当前挂单',
      inputSchema: {
        type: 'object',
        properties: {
          symbol: {
            type: 'string',
            description: '特定交易对的挂单,不传则获取所有挂单',
          },
        },
        required: [],
      },
      handler: async (binanceClient: any, args: unknown) => {
        const input = validateInput(GetOpenOrdersSchema, args);
        
        if (input.symbol) {
          validateSymbol(input.symbol);
        }
    
        try {
          const openOrders = await binanceClient.openOrders(
            input.symbol ? { symbol: input.symbol } : {}
          );
    
          return {
            symbol: input.symbol || 'ALL',
            orders: openOrders.map((order: any) => ({
              symbol: order.symbol,
              orderId: order.orderId,
              orderListId: order.orderListId,
              clientOrderId: order.clientOrderId,
              price: order.price,
              origQty: order.origQty,
              executedQty: order.executedQty,
              cummulativeQuoteQty: order.cummulativeQuoteQty,
              status: order.status,
              timeInForce: order.timeInForce,
              type: order.type,
              side: order.side,
              stopPrice: order.stopPrice,
              icebergQty: order.icebergQty,
              time: order.time,
              updateTime: order.updateTime,
              isWorking: order.isWorking,
              origQuoteOrderQty: order.origQuoteOrderQty,
            })),
            count: openOrders.length,
            timestamp: Date.now(),
          };
        } catch (error) {
          handleBinanceError(error);
        }
      },
    },
  • src/server.ts:41-50 (registration)
    Top-level registration where accountTools (including get_open_orders) are spread into allTools and registered in 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 type inferred from GetOpenOrdersSchema for input validation.
    export type GetOpenOrdersInput = z.infer<typeof GetOpenOrdersSchema>;

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