-
Notifications
You must be signed in to change notification settings - Fork 15
/
binance.py
48 lines (45 loc) · 2.13 KB
/
binance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
import time
from message import telegram_send_message
def get_position(headers, json_data, max_retries=5):
retry_count = 0
while retry_count <= max_retries:
try:
return requests.post("https://www.binance.com/bapi/futures/v1/public/future/leaderboard/getOtherPosition",
headers=headers, json=json_data)
except requests.exceptions.ConnectionError as e:
print(f"Connection error occurred: {e}")
telegram_send_message(f"Connection error occurred: {e}")
if retry_count >= max_retries:
telegram_send_message("Max retry count reached. Waiting for 10 minutes before next try...")
time.sleep(600)
retry_count = 0
else:
print("Retrying in 5 seconds...")
time.sleep(5)
retry_count += 1
def get_nickname(headers, json_data, max_retries=5):
retry_count = 0
while retry_count <= max_retries:
try:
return requests.post("https://www.binance.com/bapi/futures/v2/public/future/leaderboard/getOtherLeaderboardBaseInfo",
headers=headers, json=json_data)
except requests.exceptions.ConnectionError as e:
print(f"Connection error occurred: {e}")
telegram_send_message(f"Connection error occurred: {e}")
if retry_count >= max_retries:
telegram_send_message("Max retry count reached. Waiting for 10 minutes before next try...")
time.sleep(600)
retry_count = 0
else:
print("Retrying in 5 seconds...")
time.sleep(5)
retry_count += 1
def get_markprice(symbol):
api_url = "https://fapi.binance.com/fapi/v1/premiumIndex"
req_data = requests.get(api_url, params={"symbol": symbol})
try:
data = req_data.json()
return data['markPrice']
except Exception:
return "Market price retrieval error"