cancel_order
Cancel a specific cryptocurrency order on Binance by providing the trading pair and order ID. Ideal for managing trading strategies and adjusting market positions effectively.
Instructions
Cancel a specific order.
Args: symbol: The trading pair. order_id: Order ID to cancel.
Returns: Cancellation result.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| order_id | Yes | ||
| symbol | Yes |
Implementation Reference
- binance.py:176-202 (handler)The main handler function for the 'cancel_order' tool. It uses the Binance API to cancel a specific order by symbol and order ID. Registered via @mcp.tool() decorator.@mcp.tool() def cancel_order(symbol: str, order_id: str) -> Any: """ Cancel a specific order. Args: symbol: The trading pair. order_id: Order ID to cancel. Returns: Cancellation result. """ url = "https://api.binance.com/api/v3/order" timestamp = int(time.time() * 1000) params = { "symbol": symbol, "orderId": order_id, "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.delete(url, headers=headers, params=params) if response.status_code == 200: return {"message": f"Order {order_id} canceled"} return {"error": response.text}