add error handling and cooldown

This commit is contained in:
Aurelien Rebourg 2022-11-23 14:49:58 +01:00
parent bf2c4f18d5
commit 1234a36c4e
No known key found for this signature in database
GPG Key ID: DCA8C44ABFE7F847
1 changed files with 16 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import requests
import json import json
import traceback import traceback
import os import os
from time import sleep
from telegram import Bot, ParseMode from telegram import Bot, ParseMode
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from pathlib import Path from pathlib import Path
@ -74,15 +75,24 @@ Type: *{'🔴 Short' if position['amount'] < 0 else '🟢 Long'}*
Amount: *{abs(position['amount'])}*""" Amount: *{abs(position['amount'])}*"""
send_all(text) send_all(text)
first = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload) while True:
first_r = first.json() try:
data = get_data(first_r["data"]["otherPositionRetList"]) first = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload)
first_r = first.json()
data = get_data(first_r["data"]["otherPositionRetList"])
send_all("Bot restarted")
for position in data:
send_msg_formatted(position)
break
except Exception:
send_all(traceback.format_exc())
sleep(1)
continue
send_all("Bot restarted")
for position in data:
send_msg_formatted(position)
while True: while True:
sleep(1)
try: try:
r = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload) r = requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition", json=payload)
resp = r.json() resp = r.json()