| 
						
					 | 
				
			
			 | 
			 | 
			
				@@ -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
 | 
			
		
		
	
	
		
			
				
					
					| 
						 
							
							
							
						 
					 | 
				
			
			 | 
			 | 
			
				 
 |