Skip to main content
Glama
mixuechu

Binance MCP Server

by mixuechu

get_account_balance

Check cryptocurrency asset balances on Binance by specifying the asset symbol to monitor account holdings and track portfolio value.

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
NameRequiredDescriptionDefault
assetYes

Implementation Reference

  • The handler function for the 'get_account_balance' tool. It is registered using the @mcp.tool() decorator and implements the logic to query the Binance API for the balance of a specified asset.
    @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()

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