bybit ballance working

This commit is contained in:
Dobromir Popov
2025-07-14 23:20:01 +03:00
parent 02804ee64f
commit 5b2dd3b0b8
3 changed files with 152 additions and 46 deletions

View File

@ -168,7 +168,20 @@ class BybitInterface(ExchangeInterface):
coins = account.get('coin', [])
for coin in coins:
if coin.get('coin', '').upper() == asset.upper():
available_balance = float(coin.get('availableToWithdraw', 0))
# Try availableToWithdraw first, then equity, then walletBalance
available_str = coin.get('availableToWithdraw', '')
if available_str:
available_balance = float(available_str)
else:
# Use equity if availableToWithdraw is empty
equity_str = coin.get('equity', '')
if equity_str:
available_balance = float(equity_str)
else:
# Fall back to walletBalance
wallet_str = coin.get('walletBalance', '0')
available_balance = float(wallet_str) if wallet_str else 0.0
logger.debug(f"Balance for {asset}: {available_balance}")
return available_balance
@ -198,6 +211,14 @@ class BybitInterface(ExchangeInterface):
except Exception as e:
logger.error(f"Error getting account summary: {e}")
return {}
def get_account_info(self) -> Dict[str, Any]:
"""Get account information (alias for get_account_summary for compatibility).
Returns:
Dictionary with account information
"""
return self.get_account_summary()
def get_all_balances(self) -> Dict[str, Dict[str, float]]:
"""Get all account balances in the format expected by trading executor.
@ -217,8 +238,23 @@ class BybitInterface(ExchangeInterface):
asset = coin.get('coin', '')
if asset:
# Convert Bybit balance format to MEXC-compatible format
available = float(coin.get('availableToWithdraw', 0))
locked = float(coin.get('locked', 0))
# Handle empty string values that cause conversion errors
available_str = coin.get('availableToWithdraw', '')
locked_str = coin.get('locked', '')
equity_str = coin.get('equity', '')
wallet_str = coin.get('walletBalance', '')
# Use equity or walletBalance if availableToWithdraw is empty
if available_str:
available = float(available_str)
elif equity_str:
available = float(equity_str)
elif wallet_str:
available = float(wallet_str)
else:
available = 0.0
locked = float(locked_str) if locked_str else 0.0
balances[asset] = {
'free': available,