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