forked from kodorvan/stcs
Added connect platform
This commit is contained in:
@@ -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()
|
@@ -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="Выберите пункт меню...",
|
||||
|
Reference in New Issue
Block a user