vectorbt
vectorbt copied to clipboard
Basic TelegramBot initialization fails
Perfectly willing to accept that I have done something wrong here, but following the example from the telegram.py source code I have the following:
import pandas as pd
import vectorbt as vbt
import ccxt
import logging
from telegram.ext import CommandHandler
from .. import configuration as global_config
logging.basicConfig(level=logging.INFO)
class MyTelegramBot(vbt.TelegramBot):
@property
def custom_handlers(self):
return (CommandHandler('get', self.get),)
@property
def help_message(self):
return "Type /get [symbol] [exchange id (optional)] to get the latest price."
def get(self, update, context):
chat_id = update.effective_chat.id
if len(context.args) == 1:
symbol = context.args[0]
exchange = 'binance'
elif len(context.args) == 2:
symbol = context.args[0]
exchange = context.args[1]
else:
self.send_message(chat_id, "This command requires symbol and optionally exchange id.")
return
try:
ticker = getattr(ccxt, exchange)().fetchTicker(symbol)
except Exception as e:
self.send_message(chat_id, str(e))
return
self.send_message(chat_id, str(ticker['last']))
if __name__ == '__main__':
print(global_config.settings['telegram']['token'])
vbt.settings['messaging']['telegram']['token'] = global_config.settings['telegram']['token']
telegram_bot = MyTelegramBot(token=global_config.settings['telegram']['token'])
This fails with the following output:
(pytrade37) PS C:\Users\~\source\repos\pytrade> python -m pytrade.telegram_bot.bot
21119594~~~~~~~~~~~~~G0asnas
INFO:vectorbt.messaging.telegram:Initializing bot
Traceback (most recent call last):
File "C:\Users\~\Anaconda3\envs\pytrade37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\~\Anaconda3\envs\pytrade37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\~\source\repos\pytrade\pytrade\telegram_bot\bot.py", line 46, in <module>
telegram_bot = MyTelegramBot(token=global_config.settings['telegram']['token'])
File "C:\Users\~\Anaconda3\envs\pytrade37\lib\site-packages\vectorbt\messaging\telegram.py", line 170, in __init__
self._updater = Updater(persistence=persistence, defaults=defaults, **updater_kwargs)
File "C:\Users\~\Anaconda3\envs\pytrade37\lib\site-packages\telegram\ext\updater.py", line 237, in __init__
raise ValueError('`token` or `bot` must be passed')
ValueError: `token` or `bot` must be passed
Any help appreciated. I'm not used to python (C# for my day job). I can follow the stack trace roughly but with all the loose typing and generic argument lists being passed I can't quite follow what is going on here.
Hi @matthewaturner, I can reproduce the issue with the latest python-telegram-bot version. The fix will come out with 0.22.0. In the meantime, please use python-telegram-bot==13.4.1.
Thank you very much! This project is awesome - really appreciate you putting this out for everyone.