Update function

This commit is contained in:
algizn97
2025-08-21 13:36:11 +05:00
parent 2dc639d59a
commit 4ebe7399ba

View File

@@ -2,7 +2,8 @@
from pybit.unified_trading import HTTP from pybit.unified_trading import HTTP
client = HTTP() import logging
logging.basicConfig(level=logging.DEBUG)
async def get_balance(tg_id, message): async def get_balance(tg_id, message):
api_key = await rq.get_bybit_api_key(tg_id) api_key = await rq.get_bybit_api_key(tg_id)
@@ -15,19 +16,17 @@ async def get_balance(tg_id, message):
if api_key == 'None' or secret_key == 'None': if api_key == 'None' or secret_key == 'None':
await message.answer('⚠️ Подключите платформу для торговли') await message.answer('⚠️ Подключите платформу для торговли')
return 0 return 0
try: try:
check_user = client.get_wallet_balance() response = client.get_wallet_balance(accountType='UNIFIED')
if response['retCode'] == 0:
if check_user: total_balance = response['result']['list'][0].get('totalWalletBalance', '0')
try: return total_balance
balance = client.get_wallet_balance(accountType='UNIFIED', coin='USDT')['result']['list'][0]['coin'][0]['walletBalance'] else:
await message.answer(f"⚠️ Ошибка API: {response.get('retMsg')}")
return balance return 0
except Exception as e:
await message.answer('⚠️ Ошибка при получении баланса пользователя')
return 0
except Exception as e: except Exception as e:
await message.answer('⚠️ Неверные данные API, перепроверьте их') logging.error(f"Ошибка при получении общего баланса: {e}")
await message.answer('⚠️ Ошибка при получении баланса')
return 0 return 0