Problem, module python-telegram-bot don't work #3593
-
Hi, everyone! Need your help! Code: import telegram.ext
from telegram.ext import MessageHandler, Filters
from telegram import Bot
from binance import Client
from binance.exceptions import BinanceAPIException
# set the bot's telegram token and the chat id in which the bot will send messages
bot_token = 'your_token'
chat_id = 'your_chat_id_here'
# set the key and secret key of the Binance API
binance_api_key = 'your_api_key'
binance_api_secret = 'your_api_secret'
# create a Binance API client
client = Client(api_key=binance_api_key, api_secret=binance_api_secret)
# create a telegram bot object
bot = telegram.Bot(token=bot_token)
# function that opens crypto boxes with all stablecoins on binance
def open_stablecoin_boxes():
# list of stablecoins per binance
stablecoins = ['USDT', 'BUSD', 'USDC', 'PAX', 'TUSD', 'DAI', 'VAI', 'BIDR']
for stablecoin in stablecoins:
# try:
# open a crypto box with stablecoin on binance
client.futures_create_order(
symbol=stablecoin + 'BUSD',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_STOP_MARKET,
quantity=1,
stopPrice=0.99,
workingType=Client.WORKING_TYPE_MARK_PRICE,
priceProtect=True
)
# send a message about the opening of the crypto box to the telegram chat
bot.send_message(chat_id=chat_id, text=f'Crypto box with {stablecoin} is open!')
except BinanceAPIException as e:
# if crypto box opening failed, send an error message to telegram chat
bot.send_message(chat_id=chat_id, text=f'Error opening a crypto box with {stablecoin}: {e.message}')
# function that processes messages from the user
def handle_message(update, context):
# get the text of the message from the user
message_text = update.message.text
# check if the message text has 8 characters
if len(message_text) == 8:
# if the message text has 8 characters, open cryptoboxes with all stablecoins for binance
open_stablecoin_boxes()
# send a message about the successful opening of crypto boxes to the telegram chat
bot.send_message(chat_id=chat_id, text='Cryptoboxes with all stablecoins are open!)
else:
# if the message text does not have 8 characters, send a message about the wrong message format to the telegram chat
bot.send_message(chat_id=chat_id, text='Incorrect message format! Enter 8-digit text.')
# create a message handler registrar object for the bot's telegram
dispatcher = telegram.ext.Dispatcher(bot, None)
# register a message handler for messages from users
dispatcher.add_handler(telegram.ext.MessageHandler(telegram.ext.Filters.text, handle_message))
# start the telegram bot
bot.polling() Translated with www.DeepL.com/Translator (free version) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey. You seem to be using a version >=20.0 of python-telegram-bot but your code is written for version <=13.15. Please either upgrade your code to v20 by reading the release notes and the transition guide linked below or install a version of PTB that is compatible with your code base. Release notes: https://telegra.ph/Release-notes-for-python-telegram-bot-v200a0-05-06 Transition guide: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transition-guide-to-Version-20.0 |
Beta Was this translation helpful? Give feedback.
-
thank you very much |
Beta Was this translation helpful? Give feedback.
Hey. You seem to be using a version >=20.0 of python-telegram-bot but your code is written for version <=13.15. Please either upgrade your code to v20 by reading the release notes and the transition guide linked below or install a version of PTB that is compatible with your code base.
Please note that we only provide support for the latest stable version and that the library has undergone significant changes in v20.
Release notes: https://telegra.ph/Release-notes-for-python-telegram-bot-v200a0-05-06
Transition guide: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transition-guide-to-Version-20.0