forked from kodorvan/stcs
Update function
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
from pybit.unified_trading import HTTP
|
||||
|
||||
client = HTTP()
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
async def get_balance(tg_id, message):
|
||||
api_key = await rq.get_bybit_api_key(tg_id)
|
||||
@@ -18,16 +19,14 @@ async def get_balance(tg_id, message):
|
||||
return 0
|
||||
|
||||
try:
|
||||
check_user = client.get_wallet_balance()
|
||||
|
||||
if check_user:
|
||||
try:
|
||||
balance = client.get_wallet_balance(accountType='UNIFIED', coin='USDT')['result']['list'][0]['coin'][0]['walletBalance']
|
||||
|
||||
return balance
|
||||
except Exception as e:
|
||||
await message.answer('⚠️ Ошибка при получении баланса пользователя')
|
||||
response = client.get_wallet_balance(accountType='UNIFIED')
|
||||
if response['retCode'] == 0:
|
||||
total_balance = response['result']['list'][0].get('totalWalletBalance', '0')
|
||||
return total_balance
|
||||
else:
|
||||
await message.answer(f"⚠️ Ошибка API: {response.get('retMsg')}")
|
||||
return 0
|
||||
except Exception as e:
|
||||
await message.answer('⚠️ Неверные данные API, перепроверьте их')
|
||||
logging.error(f"Ошибка при получении общего баланса: {e}")
|
||||
await message.answer('⚠️ Ошибка при получении баланса')
|
||||
return 0
|
Reference in New Issue
Block a user