place_market_order
Execute immediate cryptocurrency trades on Binance by specifying trading pair, buy/sell direction, and quantity for instant order fulfillment.
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 |
|---|---|---|---|
| symbol | Yes | ||
| side | Yes | ||
| quantity | Yes |
Implementation Reference
- binance.py:75-104 (handler)The handler function for the 'place_market_order' tool. It is registered via the @mcp.tool() decorator and implements placing a market order on the Binance spot market using signed API requests.@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}