diff --git a/app/bybit/telegram_message_handler.py b/app/bybit/telegram_message_handler.py index 8071c03..ce9e259 100644 --- a/app/bybit/telegram_message_handler.py +++ b/app/bybit/telegram_message_handler.py @@ -67,13 +67,21 @@ class TelegramMessageHandler: closed_size = format_value(execution.get("closedSize")) symbol = format_value(execution.get("symbol")) exec_price = format_value(execution.get("execPrice")) - exec_fee = format_value(execution.get("execFee")) + exec_qty = format_value(execution.get("execQty")) + exec_fees = format_value(execution.get("execFee")) + fee_rate = format_value(execution.get("feeRate")) side = format_value(execution.get("side")) side_rus = ( "Покупка" if side == "Buy" else "Продажа" if side == "Sell" else "Нет данных" ) + if safe_float(exec_fees) == 0: + exec_fee = safe_float(exec_price) * safe_float(exec_qty) * safe_float( + fee_rate + ) + else: + exec_fee = safe_float(exec_fees) if safe_float(closed_size) == 0: await rq.set_fee_user_auto_trading( @@ -86,9 +94,7 @@ class TelegramMessageHandler: get_total_fee = user_auto_trading.total_fee total_fee = safe_float(exec_fee) + safe_float(get_total_fee) - await rq.set_total_fee_user_auto_trading( - tg_id=tg_id, symbol=symbol, total_fee=total_fee - ) + if user_auto_trading is not None and user_auto_trading.fee is not None: fee = user_auto_trading.fee @@ -109,17 +115,24 @@ class TelegramMessageHandler: ) text = f"{header}\n" f"Торговая пара: {symbol}\n" + auto_trading = ( + user_auto_trading.auto_trading if user_auto_trading else False + ) user_deals_data = await rq.get_user_deal_by_symbol( tg_id=tg_id, symbol=symbol ) - exec_bet = user_deals_data.order_quantity - base_quantity = user_deals_data.base_quantity + if user_deals_data is not None and auto_trading: + await rq.set_total_fee_user_auto_trading( + tg_id=tg_id, symbol=symbol, total_fee=total_fee + ) + text += f"Текущая ставка: {user_deals_data.order_quantity}\n" + else: + text += f"Количество: {exec_qty}\n" text += ( f"Цена исполнения: {exec_price}\n" - f"Текущая ставка: {exec_bet}\n" f"Движение: {side_rus}\n" - f"Комиссия за сделку: {exec_fee}\n" + f"Комиссия: {exec_fee:.8f}\n" ) if safe_float(closed_size) > 0: @@ -129,9 +142,6 @@ class TelegramMessageHandler: chat_id=tg_id, text=text, reply_markup=kbi.profile_bybit ) - auto_trading = ( - user_auto_trading.auto_trading if user_auto_trading else False - ) user_symbols = user_auto_trading.symbol if user_auto_trading else None if ( @@ -154,6 +164,7 @@ class TelegramMessageHandler: await rq.set_fee_user_auto_trading( tg_id=tg_id, symbol=symbol, fee=0 ) + base_quantity = user_deals_data.base_quantity await rq.set_order_quantity( tg_id=tg_id, order_quantity=base_quantity )