diff --git a/app/telegram/handlers/main_settings/additional_settings.py b/app/telegram/handlers/main_settings/additional_settings.py index 894e3ac..c792555 100644 --- a/app/telegram/handlers/main_settings/additional_settings.py +++ b/app/telegram/handlers/main_settings/additional_settings.py @@ -105,10 +105,10 @@ async def trade_mode(callback_query: CallbackQuery, state: FSMContext) -> None: await state.clear() -@router_additional_settings.callback_query(F.data == "switch_side_start") -async def switch_side_start(callback_query: CallbackQuery, state: FSMContext) -> None: +@router_additional_settings.callback_query(F.data == "switch_side_second") +async def switch_side_second(callback_query: CallbackQuery, state: FSMContext) -> None: """ - Handles the 'switch_side_start' callback query. + Handles the 'switch_side_second' callback query. Clears the current FSM state, edits the message text to display the switch side start message, and shows an inline keyboard for selection. @@ -123,13 +123,13 @@ async def switch_side_start(callback_query: CallbackQuery, state: FSMContext) -> try: await state.clear() await callback_query.message.edit_text( - text="Выберите направление первой сделки серии:\n\n" + text="Выберите направление первой сделки последующих серии:\n\n" "По направлению - сделка открывается в направлении последней сделки предыдущей серии.\n" "Противоположно - сделка открывается в противоположном направлении последней сделки предыдущей серии.\n", reply_markup=kbi.switch_side, ) logger.debug( - "Command switch_side_start processed successfully for user: %s", + "Command switch_side_second processed successfully for user: %s", callback_query.from_user.id, ) except Exception as e: @@ -137,7 +137,7 @@ async def switch_side_start(callback_query: CallbackQuery, state: FSMContext) -> text="Произошла ошибка. Пожалуйста, попробуйте позже." ) logger.error( - "Error processing command switch_side_start for user %s: %s", + "Error processing command switch_side_second for user %s: %s", callback_query.from_user.id, e, ) @@ -193,6 +193,89 @@ async def switch_side_handler(callback_query: CallbackQuery, state: FSMContext) await state.clear() +@router_additional_settings.callback_query(F.data == "switch_side_start") +async def switch_side_start(callback_query: CallbackQuery, state: FSMContext) -> None: + """ + Handles the 'switch_side_start' callback query. + + Clears the current FSM state, edits the message text to display the switch side second message, + and shows an inline keyboard for selection. + + Args: + callback_query (CallbackQuery): Incoming callback query from Telegram inline keyboard. + state (FSMContext): Finite State Machine context for the current user session. + + Logs: + Success or error messages with user identification. + """ + try: + await state.clear() + await callback_query.message.edit_text( + text="Выберите направление первой сделки:\n\n", reply_markup=kbi.side_for_switch + ) + logger.debug( + "Command switch_side_start processed successfully for user: %s", + callback_query.from_user.id, + ) + except Exception as e: + await callback_query.answer( + text="Произошла ошибка. Пожалуйста, попробуйте позже." + ) + logger.error( + "Error processing command switch_side_start for user %s: %s", + callback_query.from_user.id, + e, + ) + + +@router_additional_settings.callback_query(lambda c: c.data == "buy_switch" or c.data == "sell_switch") +async def switch_side_handler_2(callback_query: CallbackQuery, state: FSMContext) -> None: + """ + Handles callback queries related to switch side selection. + + Updates FSM context with selected switch side and persists the choice in database. + Sends an acknowledgement to user and clears FSM state afterward. + + Args: + callback_query (CallbackQuery): Incoming callback query indicating selected switch side. + state (FSMContext): Finite State Machine context for the current user session. + + Logs: + Success or error messages with user identification. + """ + try: + if callback_query.data == "sell_switch": + side = "Sell" + side_rus = "Продажа" + else: + side = "Buy" + side_rus = "Покупка" + + req = await rq.set_side( + tg_id=callback_query.from_user.id, side=side + ) + + if not req: + await callback_query.answer( + text="Произошла ошибка при смене направления. Пожалуйста, попробуйте позже." + ) + return + + await callback_query.answer(text=f"Выбрано: {side_rus}") + logger.debug( + "Switch side changed successfully for user: %s", callback_query.from_user.id + ) + except Exception as e: + await callback_query.answer(text="Произошла ошибка при смене направления.") + logger.error( + "Error processing set switch_side for user %s: %s", + callback_query.from_user.id, + e, + ) + finally: + await state.clear() + + @router_additional_settings.callback_query(F.data == "margin_type") async def settings_for_margin_type( callback_query: CallbackQuery, state: FSMContext