Path: blob/master/ invest-robot-contest_trading_bot-master/bot/handlers/insert_account_handlers.py
5936 views
from main import dp, bot1from aiogram.types import Message2from bot.keyboards.start_menu_keyboard import get_start_menu3from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton4import sqlite3 as sl5from tinkoff.invest import Client6from config.personal_data import get_token78"""910Тут представлены все хэндлеры, которые отвечают за добавление аккаунта1112"""1314"""15Выводит список всех аккаунтов16"""171819@dp.message_handler(state="*", text="Изменить Аккаунт")20async def choose_account(message: Message):21token = get_token(message.from_user.id)2223choose_account = InlineKeyboardMarkup()24with Client(str(token)) as client:25acc = client.users.get_accounts()26acc_sand = client.sandbox.get_sandbox_accounts()27for i in acc.accounts:28if i.type == 1:29choose_account.add(InlineKeyboardButton(text=f"{i.name}", callback_data=f"account:{i.id}:{i.type}:{i.access_level}"))30for i in acc_sand.accounts:31choose_account.add(InlineKeyboardButton(text=f"Песочница", callback_data=f"account:{i.id}:sandbox:{i.access_level}"))3233await message.answer("Внимание! Не забудьте остановить торговые стратегии (в случае необходимости) перед сменой "34"аккаунта!")35await message.answer("Выберите аккаунт:", reply_markup=choose_account)363738"""39Второй хэндлер, который исполняется в состоянии s_wait_figi40"""414243@dp.callback_query_handler(lambda c: c.data and c.data.startswith("account"))44async def account_finish(callback_query):45data = callback_query.data.split(":")4647account_id = data[1]48account_type = data[2]49account_access = data[3]5051connection = sl.connect("db/BotDB.db")52cursor = connection.cursor()53cursor.execute('UPDATE users SET account_id = ?, account_type = ?, account_access = ? WHERE user_id = ?;',54(str(account_id), str(account_type), str(account_access), callback_query.from_user.id))55connection.commit()5657await bot.delete_message(chat_id=callback_query.from_user.id, message_id=callback_query.message.message_id)58await bot.send_message(chat_id=callback_query.from_user.id, text=f"Аккаунт успешно изменён!",59reply_markup=get_start_menu(user_id=callback_query.from_user.id))606162