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
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | ||
| side | Yes | ||
| type | Yes | ||
| quantity | No | ||
| quoteOrderQty | No | ||
| price | No | ||
| timeInForce | No |
Implementation Reference
- src/tools/trade.ts:21-52 (handler)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); } } };
- src/tools/trade.ts:6-14 (schema)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; } }, }); });