Skip to main content
Glama
ethancod1ng
by ethancod1ng

place_order

Execute buy or sell orders on Binance exchange using market or limit order types with specified trading pairs and quantities.

Instructions

下单交易 - 支持主网和测试网(主网将使用真实资金)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
priceNo价格,LIMIT订单必需
quantityYes数量
sideYes买卖方向
symbolYes交易对符号,如 BTCUSDT
typeYes订单类型

Implementation Reference

  • The core handler function for the 'place_order' tool. It validates the input using PlaceOrderSchema, constructs the order parameters for the Binance API, executes the order, handles errors with handleBinanceError, and returns a detailed order result object.
    handler: async (binanceClient: any, args: unknown) => { const networkMode = validateAndWarnMainnet(); const input = validateInput(PlaceOrderSchema, args); validateSymbol(input.symbol); validateQuantity(input.quantity); if (input.type === 'LIMIT' && !input.price) { throw new Error('Price is required for LIMIT orders'); } if (input.price) { validatePrice(input.price); } try { const orderParams: any = { symbol: input.symbol, side: input.side, type: input.type, quantity: input.quantity, }; if (input.type === 'LIMIT' && input.price) { orderParams.price = input.price; orderParams.timeInForce = 'GTC'; } const orderResult = await binanceClient.order(orderParams); return { symbol: orderResult.symbol, orderId: orderResult.orderId, orderListId: orderResult.orderListId, clientOrderId: orderResult.clientOrderId, transactTime: orderResult.transactTime, price: orderResult.price, origQty: orderResult.origQty, executedQty: orderResult.executedQty, cummulativeQuoteQty: orderResult.cummulativeQuoteQty, status: orderResult.status, timeInForce: orderResult.timeInForce, type: orderResult.type, side: orderResult.side, fills: orderResult.fills || [], timestamp: Date.now(), network: networkMode, }; } catch (error) { handleBinanceError(error); } },
  • Zod schema definition for PlaceOrder input validation, defining properties for symbol, side, type, quantity, and optional price with descriptions.
    export const PlaceOrderSchema = z.object({ symbol: z.string().describe('交易对符号'), side: z.enum(['BUY', 'SELL']).describe('买卖方向'), type: z.enum(['MARKET', 'LIMIT']).describe('订单类型'), quantity: z.string().describe('数量'), price: z.string().optional().describe('价格,LIMIT单必需'), });
  • Registration of the 'place_order' tool in the tradingTools array export. Includes name, description, JSON inputSchema matching the Zod schema, and references the handler function. This array is imported and used in server.ts for MCP tool setup.
    { name: 'place_order', description: '下单交易 - 支持主网和测试网(主网将使用真实资金)', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: '交易对符号,如 BTCUSDT', }, side: { type: 'string', enum: ['BUY', 'SELL'], description: '买卖方向', }, type: { type: 'string', enum: ['MARKET', 'LIMIT'], description: '订单类型', }, quantity: { type: 'string', description: '数量', }, price: { type: 'string', description: '价格,LIMIT订单必需', }, }, required: ['symbol', 'side', 'type', 'quantity'], }, handler: async (binanceClient: any, args: unknown) => { const networkMode = validateAndWarnMainnet(); const input = validateInput(PlaceOrderSchema, args); validateSymbol(input.symbol); validateQuantity(input.quantity); if (input.type === 'LIMIT' && !input.price) { throw new Error('Price is required for LIMIT orders'); } if (input.price) { validatePrice(input.price); } try { const orderParams: any = { symbol: input.symbol, side: input.side, type: input.type, quantity: input.quantity, }; if (input.type === 'LIMIT' && input.price) { orderParams.price = input.price; orderParams.timeInForce = 'GTC'; } const orderResult = await binanceClient.order(orderParams); return { symbol: orderResult.symbol, orderId: orderResult.orderId, orderListId: orderResult.orderListId, clientOrderId: orderResult.clientOrderId, transactTime: orderResult.transactTime, price: orderResult.price, origQty: orderResult.origQty, executedQty: orderResult.executedQty, cummulativeQuoteQty: orderResult.cummulativeQuoteQty, status: orderResult.status, timeInForce: orderResult.timeInForce, type: orderResult.type, side: orderResult.side, fills: orderResult.fills || [], timestamp: Date.now(), network: networkMode, }; } catch (error) { handleBinanceError(error); } }, },

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