import logging.config from aiogram import Router from aiogram.fsm.context import FSMContext from aiogram.types import CallbackQuery from logger_helper.logger_helper import LOGGING_CONFIG logging.config.dictConfig(LOGGING_CONFIG) logger = logging.getLogger("close_orders") router_close_orders = Router(name="close_orders") @router_close_orders.callback_query( lambda c: c.data and c.data.startswith("close_position_") ) async def close_position_handler( callback_query: CallbackQuery, state: FSMContext ) -> None: """ Close a position. :param callback_query: Incoming callback query from Telegram inline keyboard. :param state: Finite State Machine context for the current user session. :return: None """ try: logger.debug( "Command close_position processed successfully for user: %s", callback_query.from_user.id, ) except Exception as e: await callback_query.answer(text="Произошла ошибка при закрытии позиции.") logger.error( "Error processing command close_position for user %s: %s", callback_query.from_user.id, e, ) finally: await state.clear() @router_close_orders.callback_query( lambda c: c.data and c.data.startswith("close_order_") ) async def cancel_order_handler( callback_query: CallbackQuery, state: FSMContext ) -> None: """ Cancel an order. :param callback_query: Incoming callback query from Telegram inline keyboard. :param state: Finite State Machine context for the current user session. :return: None """ try: logger.debug( "Command close_order processed successfully for user: %s", callback_query.from_user.id, ) except Exception as e: await callback_query.answer(text="Произошла ошибка при закрытии ордера.") logger.error( "Error processing command close_order for user %s: %s", callback_query.from_user.id, e, ) finally: await state.clear()