Skip to main content
Glama

binance_trade_placeOrder

Place spot market or limit orders on Binance to buy or sell cryptocurrency pairs. Specify symbol, side, order type, and quantity for execution.

Instructions

Place a spot order. Example: {symbol:'BTCUSDT', side:'BUY', type:'MARKET', quoteOrderQty:'50'}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
sideYes
typeYes
quantityNo
quoteOrderQtyNo
priceNo
timeInForceNo

Implementation Reference

  • The complete handler implementation for the 'binance_trade_placeOrder' tool, including input validation, parameter preparation, and execution via binance.newOrder API call.
    export const tool_place_order: BinanceTool = {
      name: "binance_trade_placeOrder",
      description:
        "Place a spot order. Example: {symbol:'BTCUSDT', side:'BUY', type:'MARKET', quoteOrderQty:'50'}",
      parameters: placeOrderSchema,
      async run(input) {
        ensureTradingEnabled();
        const params = placeOrderSchema.parse(input);
    
        if (params.type === "LIMIT" && !params.price) {
          throw new Error("LIMIT orders require 'price'.");
        }
    
        if (!params.quantity && !params.quoteOrderQty) {
          throw new Error("Provide 'quantity' or 'quoteOrderQty'.");
        }
    
        const payload = withCommonParams({
          quantity: params.quantity,
          quoteOrderQty: params.quoteOrderQty,
          price: params.price,
          timeInForce: params.timeInForce ?? (params.type === "LIMIT" ? "GTC" : undefined)
        });
    
        try {
          const res = await binance.newOrder(params.symbol, params.side, params.type, payload);
          return res.data;
        } catch (err) {
          throw toToolError(err);
        }
      }
    };
  • Zod schema defining the input parameters for the placeOrder tool.
    const placeOrderSchema = z.object({
      symbol: z.string().min(1),
      side: z.enum(["BUY", "SELL"]),
      type: z.enum(["MARKET", "LIMIT"]),
      quantity: z.string().optional(),
      quoteOrderQty: z.string().optional(),
      price: z.string().optional(),
      timeInForce: z.enum(["GTC", "IOC", "FOK"]).optional()
    });
  • src/index.ts:15-40 (registration)
    Registration of the tool_place_order (binance_trade_placeOrder) by including it in the tools array and registering via FastMCP server.addTool.
    const tools = [
      tool_market_price,
      tool_market_klines,
      tool_exchange_info,
      tool_account_balances,
      tool_open_orders,
      tool_place_order,
      tool_cancel_order,
    ];
    
    tools.forEach((tool) => {
      server.addTool({
        name: tool.name,
        description: tool.description,
        parameters: tool.parameters,
        execute: async (args) => {
          try {
            const result = await tool.run(args);
            return JSON.stringify(result, null, 2);
          } catch (error) {
            const handled = error instanceof ToolError ? error : new ToolError((error as Error).message);
            throw handled;
          }
        },
      });
    });

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/Valerio357/binance-mcp'

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