-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPICaller.py
More file actions
65 lines (49 loc) · 1.92 KB
/
APICaller.py
File metadata and controls
65 lines (49 loc) · 1.92 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
59
60
61
62
63
64
65
import json
import numpy
import requests
import Function
import Interval
class AlphaVantageAPI:
APIKey = "FR8QKDRVDCPIC8BB"
Function = None
Symbol = None
Interval = None
Series = None
def __init__(self):
self.Function = Function.Function.TIME_SERIES_WEEKLY
self.Interval = Interval.Interval.min_1
self.Symbol = "MSFT"
def GetTimeSeries(self, symbol = None):
#SeriesName = "Time Series (1min)"
#SeriesName = "Time Series (Daily)"
SeriesName = "Weekly Time Series"
if symbol is not None:
self.Symbol = symbol
parameters = { "function":self.Function, "symbol":self.Symbol, "apikey":"FR8QKDRVDCPIC8BB"}
resp = requests.get('https://www.alphavantage.co/query', params = parameters)
self.Series = resp.json()
#SeriesName = "Weekly Time Series"
intervalKeys = reversed(list(self.Series[SeriesName].keys()))
dataSet = []
dataSetIndex = 0
for interval in intervalKeys:
propKeys = list(self.Series[SeriesName][interval].keys())
rowSet = []
rowSet.insert(0, interval)
rowIndex = 1
for prop in propKeys:
value = self.Series[SeriesName][interval][prop]
rowSet.insert(rowIndex, value)
rowIndex = rowIndex + 1
dataSet.insert(dataSetIndex, rowSet)
dataSetIndex = dataSetIndex + 1
resp.close()
return dataSet
def TransformDataset(self, dataSet):
x = []
y = []
startPrice = dataSet[0][1]
for index in numpy.arange(0, len(dataSet)):
x.insert(index, dataSet[index][0])
y.insert(index, ((float(dataSet[index][1]) - float(startPrice))/float(startPrice)) * 100)
return x, y