-
Notifications
You must be signed in to change notification settings - Fork 7
/
binance.py
103 lines (73 loc) · 1.93 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import json
import time
import urllib3
class binance():
def __init__(self):
self.ticker = {}
self.ticker_old = {}
self.ma7=[]
self.ma77=[]
self.ma251=[]
self.tabticker = []
def checkTicker(self):
url = "https://api.binance.com/api/v1/ticker/24hr"
urllib3.disable_warnings()
http = urllib3.PoolManager()
try:
r = http.request('GET', url)
except Exception:
print('Connexion error, waiting 60s')
time.sleep(60)
self.ticker_old = self.ticker
self.ticker = json.loads(r.data.decode('utf-8'))
return self.ticker
#Check for each coin the information and return a tab of ticker
def checkAllInfoValues(self, period):
tabticker = []
for s in self.ticker:
if "BTC" in s['symbol']:
res = {}
res['symbol'] = str(s['symbol'])
url = "https://api.binance.com/api/v1/klines?symbol=" + str(s['symbol']) + "&interval=" + period +"&limit=252"
urllib3.disable_warnings()
http = urllib3.PoolManager()
try:
r = http.request('GET', url)
except Exception:
print('Connexion error, waiting 60s')
time.sleep(60)
try:
res['values'] = json.loads(r.data.decode('utf-8'))
tabticker.append(res)
except:
print("/!\ JSON empty")
self.tabticker = tabticker
return tabticker
def getListSymbol(self, ticker):
symbol = []
for s in ticker:
if s['symbol'] != '123456':
if "BTC" in s['symbol']:
symbol.append(s['symbol'])
return symbol
#Check for new symbol on the exchange
def getNewSymbol(self):
symbol = []
tickerold = []
newsymbol = []
i = 0 # check
symbol = self.getListSymbol(self.ticker)
symbolold = self.getListSymbol(self.ticker_old)
if len(symbolold) != 0:
for t in symbol:
i = 0
for told in symbolold:
if t == told:
i = 1
break
if i == 0:
newsymbol.append(t)
return newsymbol