Update function
This commit is contained in:
@@ -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)
|
||||||
@@ -18,16 +19,14 @@ async def get_balance(tg_id, message):
|
|||||||
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
|
Reference in New Issue
Block a user