-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinanceParser.py
More file actions
56 lines (49 loc) · 3.05 KB
/
Copy pathbinanceParser.py
File metadata and controls
56 lines (49 loc) · 3.05 KB
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
49
50
51
52
53
54
55
56
import requests
from datetime import datetime
def get_ticker_info_from_binance(request):
try:
names_of_coins = request[5:].split(" to ")
req = requests.get(f"https://api.binance.com/api/v1/ticker/24hr?symbol="
f"{names_of_coins[0].strip().upper()}{names_of_coins[1].strip().upper()}")
info_of_ticker = req.json()
items = ["lastPrice", "lowPrice", "highPrice", "bidPrice", "askPrice",
"weightedAvgPrice", "priceChangePercent", "volume"]
answer = f"{datetime.now().strftime('%Y-%m-%d %H:%M')}\n\n" \
f"Информация по паре {names_of_coins[0].strip()} " \
f"to {names_of_coins[1].strip()}:\n\n"
for item in items:
map_for_ticker_binance = {"lastPrice": "Цена последней сделки", "lowPrice": "Минимальная цена",
"highPrice": "Максимальная цена", "bidPrice": "Цена покупки",
"askPrice": "Цена продажи",
"weightedAvgPrice": "Средневзвешенная цена",
"priceChangePercent": "Изменение цены за сутки %",
"volume": "Объем торгов базовой валюты"}
answer += f"{map_for_ticker_binance[item]}: {info_of_ticker[item]}\n"
return answer
except Exception as ex:
print(ex)
return "Оооу... Что-то пошло не так, возможно, данная " \
"пара не торгуется на выбранной вами бирже," \
" попробуйте снова все снова:("
def get_orders_info_from_binance(request):
try:
names_of_coins = request[6:].split(" to ")
req = requests.get(f"https://api.binance.com/api/v1/depth?symbol="
f"{names_of_coins[0].strip().upper()}{names_of_coins[1].strip().upper()}&limit=5")
info_of_orders = req.json()
items = ["asks", "bids"]
answer = f"{datetime.now().strftime('%Y-%m-%d %H:%M')}\n\n" \
f"Наиболее выгодные предложения по паре" \
f" {names_of_coins[0].strip()} to {names_of_coins[1].strip()}:\n"
for item in items:
array_of_orders = info_of_orders[item]
map_for_orders_binance = {"asks": "Покупка", "bids": "Продажа"}
answer += f"\n{map_for_orders_binance[item]}:\n"
for order in array_of_orders:
answer += f"Цена: {order[0]}, Объем: {order[1]}\n"
return answer
except Exception as ex:
print(ex)
return "Оооу... Что-то пошло не так, возможно, данная " \
"пара не торгуется на выбранной вами бирже," \
" попробуйте снова все снова:("