From e61b7334a4474e79b14466b347e9848f8bb6dab9 Mon Sep 17 00:00:00 2001 From: algizn97 Date: Tue, 21 Oct 2025 13:59:09 +0500 Subject: [PATCH] The formula for calculating the number of contracts by price has been changed --- app/bybit/open_positions.py | 38 +++++---------------------- app/bybit/telegram_message_handler.py | 2 +- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/app/bybit/open_positions.py b/app/bybit/open_positions.py index 07a7d4c..1b0c401 100644 --- a/app/bybit/open_positions.py +++ b/app/bybit/open_positions.py @@ -25,11 +25,9 @@ async def start_trading_cycle( :param tg_id: Telegram user ID """ try: - client = await get_bybit_client(tg_id=tg_id) symbol = await rq.get_user_symbol(tg_id=tg_id) additional_data = await rq.get_user_additional_settings(tg_id=tg_id) risk_management_data = await rq.get_user_risk_management(tg_id=tg_id) - commission_fee = risk_management_data.commission_fee user_deals_data = await rq.get_user_deal_by_symbol( tg_id=tg_id, symbol=symbol ) @@ -43,6 +41,7 @@ async def start_trading_cycle( max_bets_in_series = additional_data.max_bets_in_series take_profit_percent = risk_management_data.take_profit_percent stop_loss_percent = risk_management_data.stop_loss_percent + total_commission = 0 get_side = "Buy" @@ -63,34 +62,6 @@ async def start_trading_cycle( else: side = "Sell" - # Get fee rates - fee_info = client.get_fee_rates(category="linear", symbol=symbol) - - # Check if commission fee is enabled - commission_fee_percent = 0.0 - if commission_fee == "Yes_commission_fee": - commission_fee_percent = safe_float( - fee_info["result"]["list"][0]["takerFeeRate"] - ) - - get_ticker = await get_tickers(tg_id, symbol=symbol) - price_symbol = safe_float(get_ticker.get("lastPrice")) or 0 - instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol) - qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep") - qty_step = safe_float(qty_step_str) - qty = safe_float(order_quantity) / safe_float(price_symbol) - decimals = abs(int(round(math.log10(qty_step)))) - qty_formatted = math.floor(qty / qty_step) * qty_step - qty_formatted = round(qty_formatted, decimals) - - if trigger_price > 0: - po_trigger_price = str(trigger_price) - else: - po_trigger_price = None - - price_for_cals = trigger_price if po_trigger_price is not None else price_symbol - total_commission = price_for_cals * qty_formatted * commission_fee_percent - await set_switch_position_mode( tg_id=tg_id, symbol=symbol, @@ -269,7 +240,7 @@ async def open_positions( instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol) qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep") qty_step = safe_float(qty_step_str) - qty = safe_float(order_quantity) / safe_float(price_symbol) + qty = (safe_float(order_quantity) * safe_float(leverage)) / safe_float(price_symbol) decimals = abs(int(round(math.log10(qty_step)))) qty_formatted = math.floor(qty / qty_step) * qty_step qty_formatted = round(qty_formatted, decimals) @@ -285,6 +256,9 @@ async def open_positions( price_for_cals = trigger_price if po_trigger_price is not None else price_symbol + if qty_formatted <= 0: + return "Order does not meet minimum order value" + if margin_type == "ISOLATED_MARGIN": liq_long, liq_short = await get_liquidation_price( tg_id=tg_id, @@ -361,5 +335,5 @@ async def open_positions( return "InvalidRequestError" except Exception as e: - logger.error("Error opening position for user %s: %s", tg_id, e) + logger.error("Error opening position for user %s: %s", tg_id, e, exc_info=True) return None diff --git a/app/bybit/telegram_message_handler.py b/app/bybit/telegram_message_handler.py index 5de198c..616cff3 100644 --- a/app/bybit/telegram_message_handler.py +++ b/app/bybit/telegram_message_handler.py @@ -140,7 +140,7 @@ class TelegramMessageHandler: 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" + text += f"Текущая ставка: {user_deals_data.order_quantity} USDT\n" else: text += f"Количество: {exec_qty}\n" -- 2.51.0