Пример #1
0
async def notify_waiting_for_target_price(message: types.Message, state: FSMContext):
    logging.debug(f'Log from {notify_waiting_for_target_price}: {message.text}')
    if not message.text:
        msg_body = "Теперь выберите ожидаемую цену (" + MarkdownFormatter.italic("например, 200.5") + "):"
        await message.reply(full_message(3, msg_body), parse_mode="Markdown")
        return
    await state.update_data(targetPrice=message.text.lower())
    await OrderNotification.next()
    end_notification_keyboard = InlineKeyboardMarkup(row_width=3)
    for names in available_end_notification.values():
        end_notification_keyboard.row(*[InlineKeyboardButton(i, callback_data=i) for i in names])
    msg_body = "Теперь выберите как долго отслеживать цену (" + MarkdownFormatter.italic(
        "m - мин., h - часы, d - дни.") + "):"
    await message.answer(full_message(4, msg_body),
                         parse_mode="Markdown", reply_markup=end_notification_keyboard)
Пример #2
0
 async def on_process_message(self, message: types.Message, _):
     if int(message.from_user.id) != int(self.access_id):
         header = MarkdownFormatter.bold('Access Denied') + '\n'
         msg_body = 'This is beta bot. You can request access by creating issue: ' \
                    'https://github.com/a0l6g0r8a9l2/investHelperBE/issues/new/choose'
         await message.answer(header + msg_body, parse_mode="Markdown")
         raise CancelHandler()
Пример #3
0
async def notify_waiting_for_ticker(message: types.Message, state: FSMContext):
    logging.debug(f'Log from {notify_waiting_for_ticker} {message.text}')
    if not message.text.lower():
        msg_body = "Введите TICKER акции (" + MarkdownFormatter.italic("например, SBER") + "):"
        await message.reply(full_message(1, msg_body))
        return

    try:
        stocks = await StockService().find_stock_by_ticker(ticker=message.text.upper())
        if stocks and len(stocks) > 0:
            current_stock = stocks.pop()
            logger.debug(f'Current stock: {current_stock}')
            msg_body = MarkdownMessageBuilder(current_stock).build_stock_find_message()
            logger.debug(f'Msg body: {msg_body}')
            await state.update_data(rest_stocks=stocks, ticker=message.text.upper(), current_stock=current_stock)
            await OrderNotification.waiting_for_approve_stock.set()
            approve_keyboard = InlineKeyboardMarkup(row_width=3)
            approve_keyboard.row(*[InlineKeyboardButton(i, callback_data=i) for i in approve_options])
            await message.answer(full_message(2, msg_body), parse_mode="Markdown",
                                 reply_markup=approve_keyboard)
        else:
            await message.reply(f'По тикеру {message.text} ничего не найдено. Пожалуйста, поверьте привильность тикера.')
    except HTTPStatusError as err:
        logger.error(f'Error trying to find stock with: {err.response.status_code}')
        await message.reply(f'Ошибка при поиске по тикеру {message.text}. Пожалуйста, попробуйте позднее.')
Пример #4
0
async def notify_waiting_for_event(message: types.Message, state: FSMContext):
    try:
        logging.debug(f'Log from notify_waiting_for_event: {message.text}')
        await state.update_data(event=message.text)
        data = await state.get_data()
        logging.debug(f'Getting data from storage in notify: {data.items()}')
        request_data = StockPriceNotificationRqBot(**data.get('current_stock').dict(),
                                                   action=data.get('action'),
                                                   targetPrice=data.get('targetPrice'),
                                                   endNotification=data.get('endNotification'),
                                                   delay=data.get('delay'),
                                                   event=data.get('event'))
        notification = await NotificationService(notification_user_data=request_data).create_notification()
        if notification:
            logging.debug(f'Log from notify_waiting_for_event, created notification: {notification}')
            notification = StockPriceNotificationReadRs(**notification)
            msg_body = MarkdownMessageBuilder(notification).build_notification_message()
            logging.debug(f'Log from notify_waiting_for_event, msg: {msg_body}')
            await message.answer(text=msg_body, parse_mode="Markdown")
        logging.debug(f'Log from notify_waiting_for_event, request_data: {request_data}')
    except Exception as err:
        err_msg = MarkdownFormatter.bold('Не удалось создать шедулер.') + '\n' + 'Пожалуйста, попробуйте позднее...'
        await message.answer(err_msg)
        logging.error(f'Error for {message.from_user.id} with args: {err.args}')
    finally:
        await state.finish()
Пример #5
0
async def notify_waiting_for_action(callback_query: types.CallbackQuery, state: FSMContext):
    logging.debug(f'Log from {notify_waiting_for_action}: {callback_query.message}')
    await state.update_data(action=callback_query.data)
    await OrderNotification.next()
    logging.debug(f'Log from {notify_waiting_for_action}: {callback_query.message.text}')
    msg_body = "Теперь выберите ожидаемую цену (" + MarkdownFormatter.italic("например, 200.5") + "):"
    await callback_query.message.answer(full_message(3, msg_body), parse_mode="Markdown")
Пример #6
0
async def notify_waiting_for_delay(callback_query: types.CallbackQuery, state: FSMContext):
    logging.debug(f'Log from {notify_waiting_for_delay}: {callback_query.data}')
    msg_body = "Можете ввести описание события, которое произойдет по достижению цены (" + \
               MarkdownFormatter.italic("Например: Цена достигла месячного минимума!") + "):"
    await state.update_data(delay=callback_query.data)
    await OrderNotification.next()
    await callback_query.message.answer(full_message(6, msg_body),
                                        parse_mode="Markdown")
Пример #7
0
async def notify_waiting_for_end_notification(callback_query: types.CallbackQuery, state: FSMContext):
    logging.debug(f'Log from {notify_waiting_for_end_notification}: {callback_query.message.text}')
    await state.update_data(endNotification=callback_query.data)
    await OrderNotification.next()
    logging.debug(f'Log from {notify_waiting_for_end_notification}: {callback_query.message.text}')
    delay_keyboard = InlineKeyboardMarkup(row_width=3)
    delay_keyboard.row(*[InlineKeyboardButton(i, callback_data=i)
                         for i in available_delay.get(callback_query.data[-1])])
    msg_body = "Теперь выберите с какой периодчностью отслеживать цену (" + \
               MarkdownFormatter.italic("s - сек., m - мин., h - часы") + "):"
    await callback_query.message.answer(full_message(5, msg_body),
                                        parse_mode="Markdown", reply_markup=delay_keyboard)
Пример #8
0
async def notify_introduce(message: types.Message):
    msg_body = "Введите TICKER акции (" + MarkdownFormatter.italic("например, MOEX") + "):"
    await message.answer(full_message(1, msg_body), parse_mode="Markdown")
    logging.debug(f'Log from {notify_introduce}: {message.text}')
    await OrderNotification.waiting_for_ticker.set()
Пример #9
0
def header(step: int) -> str:
    return MarkdownFormatter.italic(f'Шаг {step} из 7.') + '\n\n'