-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetCandleData.py
More file actions
58 lines (49 loc) · 1.55 KB
/
getCandleData.py
File metadata and controls
58 lines (49 loc) · 1.55 KB
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
# Oanda Packages
from oandapyV20 import API
import csv
access_token = "######"
params = {
"count": 4000,
"granularity": "H1",
"alignmentTimezone": "America/Los_Angeles"
}
client = API(access_token=access_token, environment="practice")
pairs = ["EUR_USD", "EUR_GBP", "EUR_AUD", "EUR_JPY", "USD_JPY", "GBP_USD", "AUD_USD"]
class main():
def __init__(self):
return
def feedData(self):
for pair in pairs:
# Call imported user1 class
o = instruments.InstrumentsCandles(instrument=pair, params=params)
client.request(o)
candles = o.response.get("candles")
# OHLC variables to return in array
self.wO = []
self.wH = []
self.wL = []
self.wC = []
self.wV = []
self.wD = []
for x in range(0, params["count"]):
candleData = candles[x].get("mid")
candleDate = candles[x].get("time")
v = candles[x].get("volume")
o = candleData.get("o")
h = candleData.get("h")
l = candleData.get("l")
c = candleData.get("c")
self.wO.append(float(o))
self.wH.append(float(h))
self.wL.append(float(l))
self.wC.append(float(c))
self.wV.append(float(v))
self.wD.append(candleDate)
# Write to CSV
with open("./dataStore/" + pair + "1H.csv", "w") as csvfile:
wr = csv.writer(csvfile, delimiter=',')
for i in range(0, len(self.wO)):
wr.writerow([self.wD[i], self.wO[i],self.wH[i],self.wL[i],self.wC[i]])
if __name__ == "__main__":
m = main()
print m.feedData()