Files
gogo2/NN/exchanges/bybit/debug/test_bybit_balance.py
2025-07-14 23:20:01 +03:00

81 lines
2.5 KiB
Python

#!/usr/bin/env python3
import os
import sys
import asyncio
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
from NN.exchanges.bybit_interface import BybitInterface
async def test_bybit_balance():
"""Test if we can read real balance from Bybit"""
print("Testing Bybit Balance Reading...")
print("=" * 50)
# Initialize Bybit interface
bybit = BybitInterface()
try:
# Connect to Bybit
print("Connecting to Bybit...")
success = await bybit.connect()
if not success:
print("ERROR: Failed to connect to Bybit")
return
print("✓ Connected to Bybit successfully")
# Test get_balance for USDT
print("\nTesting get_balance('USDT')...")
usdt_balance = await bybit.get_balance('USDT')
print(f"USDT Balance: {usdt_balance}")
# Test get_all_balances
print("\nTesting get_all_balances()...")
all_balances = await bybit.get_all_balances()
print(f"All Balances: {all_balances}")
# Check if we have any non-zero balances
print("\nBalance Analysis:")
if isinstance(all_balances, dict):
for symbol, balance in all_balances.items():
if isinstance(balance, (int, float)) and balance > 0:
print(f" {symbol}: {balance}")
elif isinstance(balance, dict):
# Handle nested balance structure
total = balance.get('total', 0) or balance.get('available', 0)
if total > 0:
print(f" {symbol}: {total}")
# Test account info if available
print("\nTesting account info...")
try:
if hasattr(bybit, 'client') and bybit.client:
# Try to get account info
account_info = bybit.client.get_wallet_balance(accountType="UNIFIED")
print(f"Account Info: {account_info}")
except Exception as e:
print(f"Account info error: {e}")
except Exception as e:
print(f"ERROR: {e}")
import traceback
traceback.print_exc()
finally:
# Cleanup
if hasattr(bybit, 'client') and bybit.client:
try:
await bybit.client.close()
except:
pass
if __name__ == "__main__":
# Run the test
asyncio.run(test_bybit_balance())