Skip to main content
Glama

binance.trade.placeOrder

Execute spot trading orders on Binance by specifying symbol, side, and order type to buy or sell cryptocurrencies.

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 async run function that implements the core logic of the binance.trade.placeOrder tool: input validation, parameter preparation, API call to binance.newOrder, and error handling.
    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 and validation 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:14-39 (registration)
    Registers the tool_place_order object (imported from trade.ts) into the FastMCP server by including it in the tools array and using a forEach loop to addTool with name, description, parameters, and wrapped execute function.
    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