diff --git a/app/bybit/open_positions.py b/app/bybit/open_positions.py index f202e12..0fa3972 100644 --- a/app/bybit/open_positions.py +++ b/app/bybit/open_positions.py @@ -132,12 +132,11 @@ async def start_trading_cycle( return None -async def trading_cycle(tg_id: int, symbol: str, reverse_side: str) -> str | None: +async def trading_cycle(tg_id: int, symbol: str, reverse_side: str, size: str) -> str | None: try: user_deals_data = await rq.get_user_deal_by_symbol(tg_id=tg_id, symbol=symbol) trade_mode = user_deals_data.trade_mode order_type = user_deals_data.order_type - order_quantity = user_deals_data.order_quantity conditional_order_type = user_deals_data.conditional_order_type margin_type = user_deals_data.margin_type leverage = user_deals_data.leverage @@ -180,7 +179,7 @@ async def trading_cycle(tg_id: int, symbol: str, reverse_side: str) -> str | Non if switch_side_mode: side = "Sell" if real_side == "Buy" else "Buy" - next_quantity = safe_float(order_quantity) * ( + next_quantity = safe_float(size) * ( safe_float(martingale_factor) ** current_step ) current_step += 1 @@ -220,7 +219,7 @@ async def trading_cycle(tg_id: int, symbol: str, reverse_side: str) -> str | Non leverage_to_sell=leverage_to_sell, order_type=order_type, conditional_order_type=conditional_order_type, - order_quantity=order_quantity, + order_quantity=current_step, limit_price=limit_price, trigger_price=trigger_price, martingale_factor=martingale_factor, diff --git a/app/telegram/handlers/start_trading.py b/app/telegram/handlers/start_trading.py index 1800ca1..5c8db9b 100644 --- a/app/telegram/handlers/start_trading.py +++ b/app/telegram/handlers/start_trading.py @@ -9,6 +9,7 @@ import app.telegram.keyboards.inline as kbi import database.request as rq from app.bybit.get_functions.get_positions import get_active_positions_by_symbol from app.bybit.open_positions import start_trading_cycle +from app.helper_functions import safe_float from logger_helper.logger_helper import LOGGING_CONFIG logging.config.dictConfig(LOGGING_CONFIG) @@ -41,14 +42,14 @@ async def start_trading(callback_query: CallbackQuery, state: FSMContext) -> Non size = deals.get("size") or 0 position_idx = deals.get("positionIdx") - if position_idx != 0 and int(size) > 0 and trade_mode == "Merged_Single": + if position_idx != 0 and safe_float(size) > 0 and trade_mode == "Merged_Single": await callback_query.answer( text="У вас есть активная позиция в режиме хеджирования. " "Открытие сделки в одностороннем режиме невозможно.", ) return - if position_idx == 0 and int(size) > 0 and trade_mode == "Both_Sides": + if position_idx == 0 and safe_float(size) > 0 and trade_mode == "Both_Sides": await callback_query.answer( text="У вас есть активная позиция в одностороннем режиме. " "Открытие сделки в режиме хеджирования невозможно.", @@ -108,7 +109,7 @@ async def start_trading_long(callback_query: CallbackQuery, state: FSMContext) - size = deals.get("size") or 0 position_idx = deals.get("positionIdx") - if position_idx == 0 and int(size) > 0: + if position_idx == 0 and safe_float(size) > 0: await callback_query.answer( text="Торговля уже запущена в одностороннем режиме для данного инструмента" ) @@ -251,13 +252,13 @@ async def start_switch(callback_query: CallbackQuery, state: FSMContext) -> None size = deals.get("size") or 0 position_idx = deals.get("positionIdx") - if position_idx == 1 and int(size) > 0 and side == "Buy": + if position_idx == 1 and safe_float(size) > 0 and side == "Buy": await callback_query.answer( text="Торговля уже запущена в режиме хеджирования на покупку для данного инструмента" ) return - if position_idx == 2 and int(size) > 0 and side == "Sell": + if position_idx == 2 and safe_float(size) > 0 and side == "Sell": await callback_query.answer( text="Торговля уже запущена в режиме хеджирования на продажу для данного инструмента" )