get_wallet_balance
Retrieve wallet balance details for specified account types (UNIFIED, CONTRACT, SPOT) and optional coin on Bybit. Provides accurate balance information for better account management.
Instructions
Get wallet balance
Args:
accountType (str): Account type (UNIFIED, CONTRACT, SPOT)
coin (Optional[str]): Coin symbol
Returns:
Dict: Wallet balance information
Example:
get_wallet_balance("UNIFIED", "BTC")
Reference:
https://bybit-exchange.github.io/docs/v5/account/wallet-balance
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountType | Yes | Account type (UNIFIED, CONTRACT, SPOT) | |
| coin | No | Coin symbol |
Implementation Reference
- src/server.py:163-192 (handler)The primary MCP tool handler for 'get_wallet_balance', decorated with @mcp.tool(). It validates inputs using Pydantic Field, calls the BybitService, handles errors, and returns the balance information.@mcp.tool() def get_wallet_balance( accountType: str = Field(description="Account type (UNIFIED, CONTRACT, SPOT)"), coin: Optional[str] = Field(default=None, description="Coin symbol") ) -> Dict: """ Get wallet balance Args: accountType (str): Account type (UNIFIED, CONTRACT, SPOT) coin (Optional[str]): Coin symbol Returns: Dict: Wallet balance information Example: get_wallet_balance("UNIFIED", "BTC") Reference: https://bybit-exchange.github.io/docs/v5/account/wallet-balance """ try: result = bybit_service.get_wallet_balance(accountType, coin) if result.get("retCode") != 0: logger.error(f"Failed to get wallet balance: {result.get('retMsg')}") return {"error": result.get("retMsg")} return result except Exception as e: logger.error(f"Failed to get wallet balance: {e}", exc_info=True) return {"error": str(e)}
- src/service.py:111-125 (helper)Helper method in BybitService class that proxies the get_wallet_balance call to the underlying HTTP client (likely pybit).def get_wallet_balance(self, accountType: str, coin: Optional[str] = None) -> Dict: """ Get wallet balance Args: accountType (str): Account type (UNIFIED, CONTRACT, SPOT) coin (Optional[str]): Coin symbol Returns: Dict: Wallet balance information """ return self.client.get_wallet_balance( accountType=accountType, coin=coin )
- src/server.py:164-167 (schema)Input schema definition using Pydantic Field annotations for MCP tool parameters, providing descriptions and defaults for validation and documentation.def get_wallet_balance( accountType: str = Field(description="Account type (UNIFIED, CONTRACT, SPOT)"), coin: Optional[str] = Field(default=None, description="Coin symbol") ) -> Dict:
- src/server.py:163-163 (registration)The @mcp.tool() decorator registers this function as an MCP tool, making it available via mcp.run().@mcp.tool()
- src/server.py:638-638 (helper)Tool description in the @mcp.prompt() function used for AI context, listing available tools.- get_wallet_balance(accountType, coin) - Get wallet balance: Retrieve wallet balance information for a specific account type and coin.