Skip to main content
Glama
mixuechu

Binance MCP Server

by mixuechu

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
NameRequiredDescriptionDefault
symbolYes
sideYes
quantityYes

Implementation Reference

  • 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}

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