place_market_order
Execute instant buy or sell orders on Binance by specifying the trading pair, side (BUY/SELL), and quantity. Simplifies cryptocurrency trading through automated market order placement.
Instructions
Place a market order to buy or sell.
Args: symbol: The trading pair, e.g., BTCUSDT. side: BUY or SELL. quantity: Amount to trade.
Returns: Order placement result.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| quantity | Yes | ||
| side | Yes | ||
| symbol | Yes |
Implementation Reference
- binance.py:75-104 (handler)The primary handler function for the 'place_market_order' MCP tool. Decorated with @mcp.tool() to register it automatically with FastMCP. Handles placing market orders on Binance spot market via signed API request.@mcp.tool() def place_market_order(symbol: str, side: str, quantity: str) -> Any: """ Place a market order to buy or sell. Args: symbol: The trading pair, e.g., BTCUSDT. side: BUY or SELL. quantity: Amount to trade. Returns: Order placement result. """ url = "https://api.binance.com/api/v3/order" timestamp = int(time.time() * 1000) params = { "symbol": symbol, "side": side, "type": "MARKET", "quantity": quantity, "timestamp": timestamp } query_string = "&".join([f"{k}={v}" for k, v in params.items()]) signature = hmac.new(BINANCE_SECRET_KEY.encode(), query_string.encode(), hashlib.sha256).hexdigest() params["signature"] = signature headers = {"X-MBX-APIKEY": BINANCE_API_KEY} response = requests.post(url, headers=headers, params=params) if response.status_code == 200: return {"message": f"{side} {quantity} {symbol} order placed"} return {"error": response.text}