-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyBinanceApi.py
67 lines (58 loc) · 1.67 KB
/
MyBinanceApi.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import logging
from binance.spot import Spot as Client
from binance.lib.utils import config_logging
import timeit
#config_logging(logging, logging.DEBUG)
spot_client = Client(base_url="https://api.binance.com")
currencylist =[]
f = open('currencyList.txt', 'r')
for line in f.readlines():
currencylist.append(line.strip())
f.close()
_avgtime = 0
def updateList():
global currencylist
currencylist = []
f = open('currencyList.txt', 'r')
for line in f.readlines():
currencylist.append(line.strip())
f.close()
def getPrice():
global _avgtime
global currencylist
result=[]
start = timeit.default_timer()
apiResult = spot_client.ticker_price()
for item in apiResult:
if currencylist.count(item["symbol"]) is not 0:
price = float(item['price'])
price = str(price)
result.append(item["symbol"]+": "+price)
stop = timeit.default_timer()
_avgtime =round((stop-start)*1000/len(currencylist),2)
#print('avg Time: ', str(time)+" ms")
return result
def getAvgResponseTime():
global _avgtime
return _avgtime
def getAll():
result = spot_client.ticker_price()
list =[]
#print(result)
#print(len(result))
num = 0
for item in result:
if (item["symbol"].find("USDT")) is not -1:
#print(item["symbol"])
num+=1
list.append(item["symbol"])
#print(num)
return list
#getAll()
# if __name__ == '__main__':
# price = spot_client.ticker_price()
# print(price)
# test ="BTCUSDT"
# for item in currencylist:
# print (float((([x["price"][0] for x in price if x["symbol"]==item]))))