FSM and help

This commit is contained in:
2025-04-17 17:43:11 +03:00
parent 14f39f6f09
commit 01d181c763
3 changed files with 107 additions and 23 deletions

View File

@ -7,15 +7,49 @@ from aiogram.types import Message
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.fsm.context import FSMContext
from aiogram import Router, F
from aiogram.fsm.state import State, StatesGroup
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.utils.chat_action import ChatActionSender
import credentials
import options
import strings
async def strategy(params):
# Custom types and vars
paramsLines = ['highEnd',
'lowEnd',
'highBreak',
'lowBreak',
'netLevelsAmount',
'netStep',
'takeDelta',
'stopDelta',
'orderSize'
]
# Custom
async def parseParams(params: str):
paramsList = params.split()
paramsDict = {}
for i in range(len(paramsLines)):
paramsDict(paramsLines[i]) = paramsList[i]
return paramsDict
# Bybit
async def strategy(pair, params):
print(params)
time.sleep(5)
print('cute')
await time.sleep(5)
print('Test succes')
result = pair + '\n' + params
return result
# Telegram
@ -25,43 +59,71 @@ async def strategy(params):
# Нижняя граница ордеров
# Верхняя граница для брейка
# Нижняя граница для брейка
# Количество уровней сетки
# Шаг сетки
# Дельта для тейка
# Дельта для стопа
# Размер позиции на каждом уровне
dp = Dispatcher()
class Form(StatesGroup):
pair = State()
params = State()
dp = Dispatcher(storage=MemoryStorage())
bot = Bot(
token=credentials.bot_token,
default=DefaultBotProperties(parse_mode=ParseMode.HTML),
)
strategy_router = Router()
# async def sendMessage(text):
# await bot.send_message(text, )
@dp.message(Command("start"))
async def commandStart(message: Message) -> None:
# chat_id = message.from_user.id
await message.answer(strings.startCommand)
@dp.message(Command("stop"))
async def commandStop(message: Message) -> None:
await message.answer(strings.stopCommand + '\n' + strings.stopStrategy)
@dp.message(Command("help"))
async def commandHelp(message: Message) -> None:
await message.answer(strings.helpCommand)
@dp.message()
async def getParams(message: Message) -> None:
params = message.text
await message.answer(strings.gotParams + '\n' + strings.startStrategy)
await strategy(params)
@strategy_router.message(Command("strategy"))
async def commandStrategy(message: Message, state: FSMContext):
print("F command strategy + capture pair")
async with ChatActionSender.typing(bot=bot, chat_id=message.chat.id):
await asyncio.sleep(1)
await message.answer(strings.strategyCommand + '\n' + strings.askPair)
await state.set_state(Form.pair)
@strategy_router.message(F.text, Form.pair)
async def capture_pair(message: Message, state: FSMContext):
print("F capture pair + capture params")
await state.update_data(pair=message.text)
async with ChatActionSender.typing(bot=bot, chat_id=message.chat.id):
await asyncio.sleep(1)
await message.answer(strings.askParams)
await state.set_state(Form.params)
@strategy_router.message(F.text, Form.params)
async def capture_params(message: Message, state: FSMContext):
print("F capture params + end")
await state.update_data(params=message.text)
data = await state.get_data()
t = await strategy(pair=data.get("pair"), params=data.get("params"))
msg_text = (f'Вы запускаете стратегию на паре <b>{data.get("pair")}</b> с данными параметрами\n<b>{data.get("params")}</b>\n')
await message.answer(msg_text)
await state.clear()
@dp.message(Command("stop"))
async def commandStop(message: Message) -> None:
await message.answer(strings.stopCommand + '\n' + strings.stopStrategy)
# Main
async def main() -> None:
dp.include_router(strategy_router)
await dp.start_polling(bot)
if __name__ == "__main__":