forked from Doaxan/crypto_arbitrage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binance.py
52 lines (39 loc) · 1.36 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
49
50
51
52
import time
import ujson
import requests
SYMBOLS = "https://api.binance.com/api/v1/exchangeInfo"
TICKER = "https://api.binance.com/api/v3/ticker/bookTicker"
def request_json(url):
global json_response
while True:
try:
r = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
json_response = ujson.loads(r.content.decode('utf-8'))
except ValueError:
print("error request_json:")
print(url)
print(r)
time.sleep(2)
continue
return json_response
def get_ticker():
return request_json(TICKER)
def get_symbols():
return request_json(SYMBOLS)
def get_buy_sell():
binance_ticker = get_ticker()
binance_symbols = get_symbols()['symbols']
# print(hitbtc_symbols)
# print("exmo:", exmo_ticker)
# print("hitbtc:", hitbtc_ticker)
# I buy, I sell
binance_buy_sell = {'name': 'binance', 'pairs': {}}
for pair in binance_ticker:
# print(pair['symbol'])
for value in binance_symbols:
if value['symbol'] == pair['symbol']:
# print(value['baseCurrency']+"_"+value['quoteCurrency'])
binance_buy_sell['pairs'][value['baseAsset'] + "_" + value['quoteAsset']] = {
'buy': pair['askPrice'], 'sell': pair['bidPrice']}
break
return binance_buy_sell