From fc8ab19ae965a49db3337a867efd087056a613aa Mon Sep 17 00:00:00 2001 From: algizn97 Date: Fri, 10 Oct 2025 14:14:46 +0500 Subject: [PATCH] Fixed the budget calculation function --- app/bybit/web_socket.py | 4 +++- app/helper_functions.py | 11 +++-------- app/telegram/handlers/settings.py | 19 +------------------ app/telegram/keyboards/reply.py | 6 ++++-- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/app/bybit/web_socket.py b/app/bybit/web_socket.py index b89fb6e..4c3579f 100644 --- a/app/bybit/web_socket.py +++ b/app/bybit/web_socket.py @@ -46,7 +46,9 @@ class WebSocketBot: self.user_sockets.clear() self.user_messages.clear() self.user_keys.clear() - logger.info("Closed old websocket for user %s due to key change", tg_id) + logger.info( + "Closed old websocket for user %s due to key change", tg_id + ) success = await self.try_connect_user(api_key, api_secret, tg_id) if success: diff --git a/app/helper_functions.py b/app/helper_functions.py index 04db1ce..07fd74d 100644 --- a/app/helper_functions.py +++ b/app/helper_functions.py @@ -158,7 +158,7 @@ async def get_liquidation_price( async def calculate_total_budget( - quantity, martingale_factor, max_steps, commission_fee_percent + quantity, martingale_factor, max_steps ) -> float: """ Calculate the total budget for a series of trading steps. @@ -167,7 +167,6 @@ async def calculate_total_budget( quantity (float): The initial quantity of the asset. martingale_factor (float): The factor by which the quantity is multiplied for each step. max_steps (int): The maximum number of trading steps. - commission_fee_percent (float): The commission fee percentage. Returns: float: The total budget for the series of trading steps. @@ -175,12 +174,8 @@ async def calculate_total_budget( total = 0 for step in range(max_steps): set_quantity = quantity * (martingale_factor**step) - if commission_fee_percent == 0: - # Commission fee is not added to the position size - r_quantity = set_quantity - else: - # Commission fee is added to the position size - r_quantity = set_quantity * (1 + 2 * commission_fee_percent) + + r_quantity = set_quantity total += r_quantity return total diff --git a/app/telegram/handlers/settings.py b/app/telegram/handlers/settings.py index ed9a914..27487d4 100644 --- a/app/telegram/handlers/settings.py +++ b/app/telegram/handlers/settings.py @@ -6,7 +6,6 @@ from aiogram.types import CallbackQuery import app.telegram.keyboards.inline as kbi import database.request as rq -from app.bybit import get_bybit_client from app.helper_functions import calculate_total_budget, safe_float from logger_helper.logger_helper import LOGGING_CONFIG @@ -26,7 +25,6 @@ async def additional_settings(callback_query: CallbackQuery, state: FSMContext) try: await state.clear() tg_id = callback_query.from_user.id - symbol = await rq.get_user_symbol(tg_id=tg_id) additional_data = await rq.get_user_additional_settings(tg_id=tg_id) if not additional_data: @@ -64,30 +62,15 @@ async def additional_settings(callback_query: CallbackQuery, state: FSMContext) max_bets = additional_data.max_bets_in_series quantity = f(additional_data.order_quantity) trigger_price = f(additional_data.trigger_price) or 0 - risk_management_data = await rq.get_user_risk_management(tg_id=tg_id) - commission_fee = risk_management_data.commission_fee - client = await get_bybit_client(tg_id=tg_id) - fee_info = client.get_fee_rates(category="linear", symbol=symbol) - - if commission_fee == "Yes_commission_fee": - commission_fee_percent = safe_float( - fee_info["result"]["list"][0]["takerFeeRate"] - ) - - else: - commission_fee_percent = 0.0 switch_side_mode = "" if trade_mode == "Switch": switch_side_mode = f"- Направление первой сделки: {switch_side}\n" - quantity_price = quantity * trigger_price - total_commission = quantity_price * commission_fee_percent total_budget = await calculate_total_budget( quantity=quantity, martingale_factor=martingale, max_steps=max_bets, - commission_fee_percent=total_commission, ) text = ( f"Основные настройки:\n\n" @@ -99,7 +82,7 @@ async def additional_settings(callback_query: CallbackQuery, state: FSMContext) f"- Коэффициент мартингейла: {martingale:.2f}\n" f"- Триггер цена: {trigger_price:.4f} USDT\n" f"- Максимальное кол-во ставок в серии: {max_bets}\n\n" - f"- Бюджет серии: {total_budget:.4f} USDT\n" + f"- Бюджет серии: {total_budget:.2f} USDT\n" ) keyboard = kbi.get_additional_settings_keyboard(mode=trade_mode) diff --git a/app/telegram/keyboards/reply.py b/app/telegram/keyboards/reply.py index fed4241..f4b8716 100644 --- a/app/telegram/keyboards/reply.py +++ b/app/telegram/keyboards/reply.py @@ -1,8 +1,10 @@ from aiogram.types import KeyboardButton, ReplyKeyboardMarkup profile = ReplyKeyboardMarkup( - keyboard=[[KeyboardButton(text="Панель Bybit"), KeyboardButton(text="Профиль")], - [KeyboardButton(text="Подключить платформу Bybit")]], + keyboard=[ + [KeyboardButton(text="Панель Bybit"), KeyboardButton(text="Профиль")], + [KeyboardButton(text="Подключить платформу Bybit")], + ], resize_keyboard=True, one_time_keyboard=True, input_field_placeholder="Выберите пункт меню...",