Skip to main content
Glama
mixuechu

Binance MCP Server

by mixuechu

get_trade_history

Retrieve recent cryptocurrency trade data for a specific trading pair on Binance to analyze market activity and transaction history.

Instructions

Get recent trade history for a pair.

Args: symbol: The trading pair. limit: Number of trades to fetch.

Returns: List of trade summaries.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
limitNo

Implementation Reference

  • The main handler function for the 'get_trade_history' tool. It is decorated with @mcp.tool() for registration and implements fetching the user's recent trade history from the Binance API endpoint /api/v3/myTrades using HMAC-signed authentication.
    @mcp.tool()
    def get_trade_history(symbol: str, limit: int = 10) -> Any:
        """
        Get recent trade history for a pair.
    
        Args:
            symbol: The trading pair.
            limit: Number of trades to fetch.
    
        Returns:
            List of trade summaries.
        """
        url = "https://api.binance.com/api/v3/myTrades"
        timestamp = int(time.time() * 1000)
        params = {
            "symbol": symbol,
            "limit": limit,
            "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.get(url, headers=headers, params=params)
        if response.status_code == 200:
            return [
                {
                    "time": trade["time"],
                    "side": "BUY" if trade["isBuyer"] else "SELL",
                    "qty": trade["qty"],
                    "price": trade["price"]
                } for trade in response.json()
            ]
        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