-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.py
68 lines (51 loc) · 2.26 KB
/
test.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
### COPIED FROM TRINITUM REPO ###
import time
import ciso8601
from datetime import datetime, timedelta
def getCurrentTimeUNIX():
return time.time()
def dateToUNIX(date): #format: "YYYYMMDD hhmmss"
ts = ciso8601.parse_datetime(date)
return time.mktime(ts.timetuple())
def getCurrentDateStr():
return time.strftime("%Y%m%d")
def datetimeDiff(datetime1, daysNum, order = "%Y%m%d"):
formattedDT = datetime1[:10].replace("-", "")
now = datetime.strptime(formattedDT, order).date()
return str(now - timedelta(days=daysNum)).replace("-", "")
GDAX_TO_POLONIEX = {'BTC-USD': "USDT_BTC", 'LTC-USD': "USDT_LTC", 'ETH-USD': "USDT_ETC"}
class Pipeline(object):
def __init__(self, interval):
self.interval = interval
self.POLO_URL = 'https://poloniex.com/public'
self.POLO_HIST_DATA = self.POLO_URL + '?command=returnChartData¤cyPair={}&start={}&end={}&period={}'
def getCryptoHistoricalData(self, symbol, endTime, histPeriod, vwap=False):
endTimeUNIX = dateToUNIX(endTime)
startDate = getCurrentDateStr()
priorDate = datetimeDiff(startDate, histPeriod)
gdaxTicker = GDAX_TO_POLONIEX[symbol]
stDateUNIX = dateToUNIX(priorDate)
eDateUNIX = dateToUNIX(startDate)
poloniexJsonURL = self.POLO_HIST_DATA.format(gdaxTicker, stDateUNIX, eDateUNIX, self.interval)
import json
import requests
poloniexJson = requests.get(poloniexJsonURL).json()
from pandas import DataFrame
histDataframe = DataFrame.from_records(poloniexJson)
histDataframe.drop('quoteVolume', axis=1, inplace=True)
histDataframe.drop('weightedAverage', axis=1, inplace=True)
histDataframe['date'] = histDataframe['date'].astype(float)
return histDataframe[["date", "open", "high", "low", "close", "volume"]]
""" # TEST RTT
if __name__ == '__main__':
pl = Pipeline(interval=300)
df = pl.getCryptoHistoricalData(symbol='BTC-USD', endTime='20180201', histPeriod=30)
from realtime_talib import Indicator
obv = Indicator(df, 'OBV')
trix = Indicator(df, 'TRIX', 20)
rocr = Indicator(df, 'ROCR', 20)
atr = Indicator(df, 'ATR', 20)
print(obv.getHistorical(), trix.getHistorical(), rocr.getHistorical(), atr.getHistorical())
test_ohlcv = [4000, 4100, 3900, 4200, 960]
print(obv.getRealtime(test_ohlcv), trix.getRealtime(test_ohlcv), rocr.getRealtime(test_ohlcv), atr.getRealtime(test_ohlcv))
"""