forked from kodorvan/stcs
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import app.telegram.database.requests as rq
|
|
|
|
from pybit.unified_trading import 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)
|
|
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:
|
|
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:
|
|
logging.error(f"Ошибка при получении общего баланса: {e}")
|
|
await message.answer('⚠️ Ошибка при получении баланса')
|
|
return 0 |