/
timeseries.py
150 lines (123 loc) · 5.76 KB
/
timeseries.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from .alphavantage import AlphaVantage as av
class TimeSeries(av):
"""This class implements all the api calls to times series
"""
@av._output_format
@av._call_api_on_func
def get_intraday(self, symbol, interval='15min', outputsize='compact'):
""" Return intraday time series in two json objects as data and
meta_data. It raises ValueError when problems arise
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
interval: time interval between two conscutive values,
supported values are '1min', '5min', '15min', '30min', '60min'
(default '15min')
outputsize: The size of the call, supported values are
'compact' and 'full; the first returns the last 100 points in the
data series, and 'full' returns the full-length intraday times
series, commonly above 1MB (default 'compact')
"""
_FUNCTION_KEY = "TIME_SERIES_INTRADAY"
return _FUNCTION_KEY, "Time Series ({})".format(interval), 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_daily(self, symbol, outputsize='compact'):
""" Return daily time series in two json objects as data and
meta_data. It raises ValueError when problems arise
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
outputsize: The size of the call, supported values are
'compact' and 'full; the first returns the last 100 points in the
data series, and 'full' returns the full-length daily times
series, commonly above 1MB (default 'compact')
"""
_FUNCTION_KEY = "TIME_SERIES_DAILY"
return _FUNCTION_KEY, 'Time Series (Daily)', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_daily_adjusted(self, symbol, outputsize='compact'):
""" Return daily adjusted (date, daily open, daily high, daily low,
daily close, daily split/dividend-adjusted close, daily volume)
time series in two json objects as data and
meta_data. It raises ValueError when problems arise
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
outputsize: The size of the call, supported values are
'compact' and 'full; the first returns the last 100 points in the
data series, and 'full' returns the full-length daily times
series, commonly above 1MB (default 'compact')
"""
_FUNCTION_KEY = "TIME_SERIES_DAILY_ADJUSTED"
return _FUNCTION_KEY, 'Time Series (Daily)', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_weekly(self, symbol):
""" Return weekly time series in two json objects as data and
meta_data. It raises ValueError when problems arise
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
"""
_FUNCTION_KEY = "TIME_SERIES_WEEKLY"
return _FUNCTION_KEY, 'Weekly Time Series', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_weekly_adjusted(self, symbol):
""" weekly adjusted time series (last trading day of each week,
weekly open, weekly high, weekly low, weekly close, weekly adjusted
close, weekly volume, weekly dividend) of the equity specified,
covering up to 20 years of historical data.
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
"""
_FUNCTION_KEY = "TIME_SERIES_WEEKLY_ADJUSTED"
return _FUNCTION_KEY, 'Weekly Adjusted Time Series', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_monthly(self, symbol):
""" Return monthly time series in two json objects as data and
meta_data. It raises ValueError when problems arise
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
"""
_FUNCTION_KEY = "TIME_SERIES_MONTHLY"
return _FUNCTION_KEY, 'Monthly Time Series', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_monthly_adjusted(self, symbol):
""" Return monthly time series in two json objects as data and
meta_data. It raises ValueError when problems arise
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
"""
_FUNCTION_KEY = "TIME_SERIES_MONTHLY_ADJUSTED"
return _FUNCTION_KEY, 'Monthly Adjusted Time Series', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_batch_stock_quotes(self, symbols):
""" Return multiple stock quotes with a single request.
It raises ValueError when problems arise
Keyword Arguments:
symbols: A tuple or list Sof symbols to query
"""
_FUNCTION_KEY = "BATCH_STOCK_QUOTES"
return _FUNCTION_KEY, 'Stock Quotes', 'Meta Data'
@av._output_format
@av._call_api_on_func
def get_quote_endpoint(self, symbol):
""" Return the latest price and volume information for a
security of your choice
Keyword Arguments:
symbol: the symbol for the equity we want to get its data
"""
_FUNCTION_KEY = "GLOBAL_QUOTE"
return _FUNCTION_KEY, 'Global Quote', None
@av._output_format
@av._call_api_on_func
def get_symbol_search(self, keywords):
""" Return best matching symbols and market information
based on keywords. It raises ValueError when problems arise
Keyword Arguments:
keywords: the keywords to query on
"""
_FUNCTION_KEY = "SYMBOL_SEARCH"
return _FUNCTION_KEY, 'bestMatches', None