Path: blob/master/ invest-robot-contest_trading_bot-master/bot/handlers/strategy_handlers.py
5935 views
from main import dp1from aiogram.types import Message2from aiogram.dispatcher.filters import Text3from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardRemove4import sqlite3 as sl5from aiogram.dispatcher.filters.state import State, StatesGroup6from bot.keyboards.start_menu_keyboard import get_start_menu7from aiogram.dispatcher import FSMContext8910'''11Выводит варианты алготрейдинга12'''131415@dp.message_handler(text="Торговые стратегии")16async def algo_trade(message: Message):17await message.answer(f"Выберите торговую стратегию:\n")1819str1_keyboard = InlineKeyboardMarkup()20str1_keyboard.add(InlineKeyboardButton(text="Торговля", callback_data="str1:list"))21str1_keyboard.add(22InlineKeyboardButton(text="Добавить бумагу в стратегию", callback_data="str1:settings:add:start"))23str1_keyboard.add(24InlineKeyboardButton(text="Удалить бумагу из стратегии", callback_data="str1:settings:delete:start"))2526await message.answer(f"EMA + ADX + MACD\n", reply_markup=str1_keyboard)272829class DeleteStrategy(StatesGroup):30wait_yes_or_no = State()313233@dp.message_handler(Text(contains="Удалить все торговые стратегии", ignore_case=True))34async def delete_all_strategies_start(message: Message):35text = ""3637connection = sl.connect("db/BotDB.db")38cursor = connection.cursor()3940strategies = cursor.execute('SELECT account_id, account_type, name FROM str1_config WHERE user_id = ?', (message.from_user.id,))4142for line in strategies:43text += f"ID аккаунта: {line[0]}\n"44if line[1] == "sandbox":45text += f"Песочница\n"46elif line[1] == "1":47text += f"Брокерский счёт\n"48text += f"Бумаги {line[2]}\n\n"4950if text:51await message.answer(f"Все открытые стратегии стратегии:\n")52await message.answer(text)53await DeleteStrategy.wait_yes_or_no.set()5455await message.answer(56f"Напишите <b>ДА</b> для удаления всех торговых стратегий.\n\nНапишите <b>НЕТ</b> для отмены.",57reply_markup=ReplyKeyboardRemove())5859else:60await message.answer("У Вас нет открытых стратегий!")616263@dp.message_handler(state=DeleteStrategy.wait_yes_or_no)64async def delete_all_strategies_finish(message: Message, state: FSMContext):6566if message.text.upper() == "ДА":67connection = sl.connect("db/BotDB.db")68cursor = connection.cursor()6970cursor.execute('DELETE FROM str1_config WHERE user_id = ?',71(message.from_user.id,))7273connection.commit()7475await state.reset_state()7677await message.answer("Все стратегии были удалены!", reply_markup=get_start_menu(message.from_user.id))7879elif message.text.upper() == "НЕТ":8081await state.reset_state()8283await message.answer("Операция отменена!", reply_markup=get_start_menu(message.from_user.id))8485else:86await message.answer("Введите <b>ДА</b> или <b>НЕТ</b>!")8788899091