-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunMe.py
59 lines (47 loc) · 1.46 KB
/
runMe.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
#
# CoinbaseExchange/runMe.py
# Daniel Paquin
#
# Technical Indicators
#
import Coinbase
from CandlestickDO import CandlestickDO
from CandleArrayDO import CandleArrayDO
from pprint import pprint
# Initialize Coinbase API Object
cbExchange = Coinbase.Coinbase()
"""
This script grabs the candles, packages them into a data object, and passes that into
a function that calculates the RSI value for that historical data set.
"""
# Get Start Time
startTime = "2015-12-20T18:23:24.865Z"
# Get End Time
response = cbExchange.getServerTime()
endTime = response['iso']
# Get Granularity- in seconds
granularity = 60*60
# Make call to CB Exchange
response = cbExchange.getCandlesticks(startTime = startTime, endTime = endTime, granularity = granularity)
# Organize data
CandlestickArray = []
for eachCandle in response:
# Package candle objects into an array
Candlestick = CandlestickDO()
Candlestick.time = eachCandle[0]
Candlestick.low = eachCandle[1]
Candlestick.high = eachCandle[2]
Candlestick.open = eachCandle[3]
Candlestick.close = eachCandle[4]
Candlestick.volume = eachCandle[5]
CandlestickArray.append(Candlestick)
GraphData = CandleArrayDO(CandlestickArray)
calcRSI = GraphData.RSI(14)
print "RSI =", calcRSI
calcSMA = GraphData.SMA(20)
print "SMA(20) =", calcSMA
calcEMA = GraphData.EMA(14, 0.5)
print "EMA(14, 0.5) =", calcEMA
calcpercentR = GraphData.percentR(14)
print "%R(14) =", calcpercentR
print startTime, endTime, granularity