1
0
forked from kodorvan/stcs
Files
stcs/app/services/Bybit/functions/balance.py

33 lines
1.1 KiB
Python

import app.telegram.database.requests as rq
from pybit.unified_trading import HTTP
client = HTTP()
async def get_balance(tg_id, message):
api_key = await rq.get_bybit_api_key(tg_id)
secret_key = await rq.get_bybit_secret_key(tg_id)
client = HTTP(
api_key=api_key,
api_secret=secret_key
)
if api_key == 'None' or secret_key == 'None':
await message.answer('⚠️ Подключите платформу для торговли')
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('⚠️ Ошибка при получении баланса пользователя')
return 0
except Exception as e:
await message.answer('⚠️ Неверные данные API, перепроверьте их')
return 0