get_account_balance
Retrieve the balance of a specific cryptocurrency asset on Binance. Input the asset symbol (e.g., BTC) to receive detailed balance information for accurate account management.
Instructions
Get the balance of a specific cryptocurrency asset.
Args: asset: The cryptocurrency symbol, e.g., BTC.
Returns: Asset balance info.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asset | Yes |
Implementation Reference
- binance.py:47-72 (handler)The handler function for the 'get_account_balance' tool. It makes an authenticated GET request to the Binance /api/v3/account endpoint to retrieve account balances, finds the specific asset's free balance, and returns it. Decorated with @mcp.tool() for registration.@mcp.tool() def get_account_balance(asset: str) -> Any: """ Get the balance of a specific cryptocurrency asset. Args: asset: The cryptocurrency symbol, e.g., BTC. Returns: Asset balance info. """ url = "https://api.binance.com/api/v3/account" timestamp = int(time.time() * 1000) params = {"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: balances = response.json().get("balances", []) for balance in balances: if balance["asset"] == asset: return {"asset": asset, "balance": balance["free"]} return {"error": f"No balance found for {asset}"} return {"error": response.text}
- binance.py:47-47 (registration)The @mcp.tool() decorator registers the get_account_balance function as an MCP tool.@mcp.tool()
- binance.py:49-57 (schema)Docstring defining the input (asset: str) and output format for the tool.""" Get the balance of a specific cryptocurrency asset. Args: asset: The cryptocurrency symbol, e.g., BTC. Returns: Asset balance info. """