From 5da00dbaa1747f5efe626fbc1278031544b31b99 Mon Sep 17 00:00:00 2001 From: algizn97 Date: Sat, 4 Oct 2025 11:04:08 +0500 Subject: [PATCH] Added connect platform --- app/telegram/handlers/handlers_main.py | 74 +++++++++++++++++++++++--- app/telegram/keyboards/reply.py | 3 +- 2 files changed, 70 insertions(+), 7 deletions(-) diff --git a/app/telegram/handlers/handlers_main.py b/app/telegram/handlers/handlers_main.py index d3b6907..5efb478 100644 --- a/app/telegram/handlers/handlers_main.py +++ b/app/telegram/handlers/handlers_main.py @@ -53,7 +53,7 @@ async def cmd_start(message: Message, state: FSMContext) -> None: await rq.create_user_conditional_settings(tg_id=tg_id) await message.answer( text=f"Добро пожаловать, {full_name}!\n\n" - "PHANTOM TRADING - ваш надежный помощник для автоматизации трейдинга😉", + "PHANTOM TRADING - ваш надежный помощник для автоматизации трейдинга😉", reply_markup=kbi.connect_the_platform, ) logger.debug( @@ -134,7 +134,7 @@ async def profile_bybit(message: Message, state: FSMContext) -> None: @router_handlers_main.callback_query(F.data == "profile_bybit") async def profile_bybit_callback( - callback_query: CallbackQuery, state: FSMContext + callback_query: CallbackQuery, state: FSMContext ) -> None: """ Handle callback query with data "profile_bybit". @@ -200,6 +200,67 @@ async def settings(callback_query: CallbackQuery, state: FSMContext) -> None: ) +@router_handlers_main.message(Command("connect")) +@router_handlers_main.message(F.text == "Подключить платформу Bybit") +async def cmd_connect(message: Message, state: FSMContext) -> None: + """ + Handle the /connect command or text "Подключить платформу Bybit". + + Clears FSM state and sends a connection message. + + Args: + message (Message): Incoming Telegram message object. + state (FSMContext): FSM state context. + + Raises: + None: Exceptions are caught and logged internally. + """ + try: + await state.clear() + user = await rq.get_user(tg_id=message.from_user.id) + if user: + await message.answer( + text=( + "Подключение Bybit аккаунта \n\n" + "1. Зарегистрируйтесь или войдите в свой аккаунт на Bybit по ссылке: " + "[Перейти на Bybit](https://www.bybit.com/invite?ref=YME83OJ).\n" + "2. В личном кабинете выберите раздел API. \n" + "3. Создание нового API ключа\n" + " - Нажмите кнопку Create New Key (Создать новый ключ).\n" + " - Выберите системно-сгенерированный ключ.\n" + " - Укажите название API ключа (любое). \n" + " - Выберите права доступа для торговли (Trade). \n" + " - Можно ограничить доступ по IP для безопасности.\n" + "4. Подтверждение создания\n" + " - Подтвердите создание ключа.\n" + " - Отправьте чат-роботу.\n\n" + "Важно: сохраните отдельно API Key и Secret Key в надежном месте. Secret ключ отображается только один раз." + ), + parse_mode="Markdown", + reply_markup=kbi.add_bybit_api, + disable_web_page_preview=True, + ) + else: + await rq.create_user( + tg_id=message.from_user.id, username=message.from_user.username + ) + await rq.set_user_symbol(tg_id=message.from_user.id, symbol="BTCUSDT") + await rq.create_user_additional_settings(tg_id=message.from_user.id) + await rq.create_user_risk_management(tg_id=message.from_user.id) + await rq.create_user_conditional_settings(tg_id=message.from_user.id) + await cmd_connect(message=message, state=state) + logger.debug( + "Command connect processed successfully for user: %s", + message.from_user.id, + ) + except Exception as e: + logger.error( + "Error processing command connect for user %s: %s", + message.from_user.id, + e, + ) + + @router_handlers_main.message(Command("help")) async def cmd_help(message: Message, state: FSMContext) -> None: """ @@ -218,9 +279,10 @@ async def cmd_help(message: Message, state: FSMContext) -> None: await state.clear() await message.answer( text="Используйте одну из следующих команд:\n" - "/start - Запустить бота\n" - "/profile - Профиль\n" - "/bybit - Панель Bybit\n", + "/start - Запустить бота\n" + "/profile - Профиль\n" + "/bybit - Панель Bybit\n" + "/connect - Подключиться к платформе\n", reply_markup=kbr.profile, ) logger.debug( @@ -316,4 +378,4 @@ async def cmd_cancel(callback_query: CallbackQuery, state: FSMContext) -> None: e, ) finally: - await state.clear() + await state.clear() \ No newline at end of file diff --git a/app/telegram/keyboards/reply.py b/app/telegram/keyboards/reply.py index d055976..fed4241 100644 --- a/app/telegram/keyboards/reply.py +++ b/app/telegram/keyboards/reply.py @@ -1,7 +1,8 @@ from aiogram.types import KeyboardButton, ReplyKeyboardMarkup profile = ReplyKeyboardMarkup( - keyboard=[[KeyboardButton(text="Панель Bybit"), KeyboardButton(text="Профиль")]], + keyboard=[[KeyboardButton(text="Панель Bybit"), KeyboardButton(text="Профиль")], + [KeyboardButton(text="Подключить платформу Bybit")]], resize_keyboard=True, one_time_keyboard=True, input_field_placeholder="Выберите пункт меню...",