-
Notifications
You must be signed in to change notification settings - Fork 0
/
wazirxHelper.py
65 lines (57 loc) · 2.35 KB
/
wazirxHelper.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
from datetime import datetime, timedelta
import sys
class WazirXHelper:
def __init__(self, creds, requestInstance, loggerInstance):
self.creds = creds
self.requestInstance = requestInstance
self.loggerInstance = loggerInstance
self.totalAmount = 0
def checkSystemHealth(self):
try:
return self.requestInstance.getURI('/systemStatus')
except Exception as e:
self.loggerInstance.logError(str(e))
sys.exit(1)
def priceChangeStatistics24Hr(self, symbol=None):
try:
tickerPriceChangeEndpoint = '/tickers/24hr'
if symbol:
tickerPriceChangeEndpoint = '/ticker/24hr?symbol=' + symbol
return self.requestInstance.getURI(tickerPriceChangeEndpoint)
except Exception as e:
self.loggerInstance.logError(str(e))
sys.exit()
def kLineData(self, symbol=None, limit=None, interval=None, startTime=None, endTime=None):
try:
if not symbol:
raise Exception('symbol is required.')
if not interval:
raise Exception('interval is required.')
kLineDataEndpoint = '/klines?symbol='+symbol+'&interval='+interval
if startTime:
kLineDataEndpoint += '&startTime='+str(int(startTime))
if endTime:
kLineDataEndpoint += '&endTime='+str(int(endTime))
if limit:
kLineDataEndpoint += '&limit='+str(limit)
return self.requestInstance.getURI(kLineDataEndpoint)
except Exception as e:
self.loggerInstance.logError(str(e))
sys.exit()
def kLineDataBeforeXMin(self, symbol=None, limit=None, minutes=30):
try:
if not symbol:
raise Exception('symbol is required.')
interval = 1
utcTimeNow = datetime.utcnow()
utcTime30MinsBefore = utcTimeNow - \
timedelta(minutes=minutes)
epochTime = datetime(1970, 1, 1)
totalSeconds30MinsBefore = (
utcTime30MinsBefore - epochTime).total_seconds()
return self.kLineData(symbol, limit, str(interval)+'m', totalSeconds30MinsBefore)
except Exception as e:
self.loggerInstance.logError(str(e))
sys.exit()
def __del__(self):
pass