Skip to main content
Glama
mixuechu

Binance MCP Server

by mixuechu

cancel_order

Cancel an active trading order on Binance by specifying the trading pair and order ID to manage your cryptocurrency positions.

Instructions

Cancel a specific order.

Args: symbol: The trading pair. order_id: Order ID to cancel.

Returns: Cancellation result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
order_idYes

Implementation Reference

  • The main handler function for the 'cancel_order' tool, decorated with @mcp.tool() for registration. It cancels a specific order on Binance using the API, authenticating with HMAC signature.
    @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}

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/mixuechu/binance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server