from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
import time
import requests
import hashlib
import logging
# Set up logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Add your ByBit API key and secret here
api_key = 'l'
api_secret = ''
signal_counter = {}
def start(update, context):
buttons = [
[InlineKeyboardButton(f"Period: {context.user_data.get('period', 15)} mins", callback_data='period')],
[InlineKeyboardButton(f"Interest %: {context.user_data.get('interest', 5)}%", callback_data='interest')]
]
reply_markup = InlineKeyboardMarkup(buttons)
update.message.reply_text('Select setting:', reply_markup=reply_markup)
def get_open_interest():
timestamp = int(time.time())
sign_string = f'api_key={api_key}×tamp={timestamp}&api_secret={api_secret}'
sign = hashlib.sha256(sign_string.encode('utf-8')).hexdigest()
headers = {
'Content-Type': 'application/json',
'Authorization': f'{api_key}:{timestamp}:{sign}'
}
api_endpoint = 'https://api.bybit.com/public/liquidation-data'
response = requests.get(api_endpoint, headers=headers)
if response.status_code == 200:
data = response.json()
return data
else:
logging.error('Error fetching open interest data: %s', response.status_code)
return None
def monitor_open_interest(context):
bot = context.bot
open_interest_data = get_open_interest()
if open_interest_data:
for pair_data in open_interest_data['result']:
symbol = pair_data['symbol']
open_interest = pair_data['openInterest']
if context.user_data.get('interest') and open_interest > context.user_data['interest']:
open_interest_percentage = pair_data['openInterestPercentage']
price_change = pair_data['priceChange']
signal_for_day = pair_data['signalForDay']
signal_counter[symbol] = signal_counter.get(symbol, 0) + 1
message = f"ByBit-15m-{symbol}\n" \
f"OI increased by {open_interest_percentage:.2f}% ({price_change:.2f}m$)\n" \
f"Price change: {price_change:.2f}%\n" \
f"Signal counter for the day: {signal_counter.get(symbol, 0)}"
# Send message
chat_id = context.job.context.message.chat_id # Access chat_id from context
bot.send_message(chat_id=chat_id, text=message)
break
time.sleep(context.user_data.get('period', 15) * 60)
def button(update, context):
query = update.callback_query
query.answer()
chat_id = query.message.chat_id # Extract chat ID from the callback query's message
if query.data == 'period':
query.edit_message_text(text="Select a period")
elif query.data == 'interest':
query.edit_message_text(text="Select interest percentage")
context.bot.send_message(chat_id=chat_id, text="Some message here") # Send a message to the chat based on the callback
def main():
updater = Updater("YOUR_BOT_TOKEN", use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CallbackQueryHandler(button))
job_queue = updater.job_queue
job_queue.run_repeating(monitor_open_interest, interval=900)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
Так а выдает что, как не запускается?
Вот пишет такую ошибку при запуске там я ток токен телеграм бота сократилTraceback (most recent call last):
File “/home/cryptopank/vse.py”, line 103, in
main()
File “/home/cryptopank/vse.py”, line 89, in main
updater = Updater(token=“6юAvLlA6D413mxj5tY”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Updater.init() got an unexpected keyword argument ‘token’
Наверно код был для старой версии библиотеки, тут у этого класса другие параметры Updater - python-telegram-bot v20.7
Так что либо разбираться как работать с новой, либо установить старую.
Спасибо большое