get_trade_history
Retrieve recent trade data for a specific cryptocurrency pair on Binance. Specify the symbol and limit to fetch detailed trade summaries for analysis or decision-making.
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
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| symbol | Yes |
Implementation Reference
- binance.py:107-140 (handler)The handler function for the 'get_trade_history' tool. It is decorated with @mcp.tool() for registration in the MCP server and implements the logic to fetch authenticated trade history from the Binance API, returning a list of trade summaries or an error.@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}