From 201cd6a6a782917e4ac84b3dbb6727d68f087f72 Mon Sep 17 00:00:00 2001 From: Alex Loukissas Date: Wed, 9 Oct 2019 18:17:12 -0700 Subject: [PATCH 1/8] Send requests over https by default --- alpha_vantage/alphavantage.py | 2 +- test_alpha_vantage/test_alphavantage.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/alpha_vantage/alphavantage.py b/alpha_vantage/alphavantage.py index 67c7481..c591af7 100644 --- a/alpha_vantage/alphavantage.py +++ b/alpha_vantage/alphavantage.py @@ -16,7 +16,7 @@ class AlphaVantage(object): """ Base class where the decorators and base function for the other classes of this python wrapper will inherit from. """ - _ALPHA_VANTAGE_API_URL = "http://www.alphavantage.co/query?" + _ALPHA_VANTAGE_API_URL = "https://www.alphavantage.co/query?" _ALPHA_VANTAGE_MATH_MAP = ['SMA', 'EMA', 'WMA', 'DEMA', 'TEMA', 'TRIMA', 'T3', 'KAMA', 'MAMA'] _ALPHA_VANTAGE_DIGITAL_CURRENCY_LIST = \ diff --git a/test_alpha_vantage/test_alphavantage.py b/test_alpha_vantage/test_alphavantage.py index 359d2c6..8630164 100644 --- a/test_alpha_vantage/test_alphavantage.py +++ b/test_alpha_vantage/test_alphavantage.py @@ -59,7 +59,7 @@ def test_time_series_intraday(self, mock_request): """ Test that api call returns a json file as requested """ ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST) - url = "http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" + url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" path_file = self.get_file_from_url("mock_time_series") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -74,7 +74,7 @@ def test_time_series_intraday_pandas(self, mock_request): """ ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST, output_format='pandas') - url = "http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" + url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" path_file = self.get_file_from_url("mock_time_series") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -90,7 +90,7 @@ def test_time_series_intraday_date_indexing(self, mock_request): """ ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST, output_format='pandas', indexing_type='date') - url = "http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" + url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" path_file = self.get_file_from_url("mock_time_series") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -110,7 +110,7 @@ def test_time_series_intraday_date_integer(self, mock_request): """ ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST, output_format='pandas', indexing_type='integer') - url = "http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" + url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&outputsize=full&apikey=test&datatype=json" path_file = self.get_file_from_url("mock_time_series") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -123,7 +123,7 @@ def test_technical_indicator_sma_python3(self, mock_request): """ Test that api call returns a json file as requested """ ti = TechIndicators(key=TestAlphaVantage._API_KEY_TEST) - url = "http://www.alphavantage.co/query?function=SMA&symbol=MSFT&interval=15min&time_period=10&series_type=close&apikey=test" + url = "https://www.alphavantage.co/query?function=SMA&symbol=MSFT&interval=15min&time_period=10&series_type=close&apikey=test" path_file = self.get_file_from_url("mock_technical_indicator") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -138,7 +138,7 @@ def test_technical_indicator_sma_pandas(self, mock_request): """ ti = TechIndicators( key=TestAlphaVantage._API_KEY_TEST, output_format='pandas') - url = "http://www.alphavantage.co/query?function=SMA&symbol=MSFT&interval=15min&time_period=10&series_type=close&apikey=test" + url = "https://www.alphavantage.co/query?function=SMA&symbol=MSFT&interval=15min&time_period=10&series_type=close&apikey=test" path_file = self.get_file_from_url("mock_technical_indicator") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -152,7 +152,7 @@ def test_sector_perfomance_python3(self, mock_request): """ Test that api call returns a json file as requested """ sp = SectorPerformances(key=TestAlphaVantage._API_KEY_TEST) - url = "http://www.alphavantage.co/query?function=SECTOR&apikey=test" + url = "https://www.alphavantage.co/query?function=SECTOR&apikey=test" path_file = self.get_file_from_url("mock_sector") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -166,7 +166,7 @@ def test_sector_perfomance_pandas(self, mock_request): """ sp = SectorPerformances( key=TestAlphaVantage._API_KEY_TEST, output_format='pandas') - url = "http://www.alphavantage.co/query?function=SECTOR&apikey=test" + url = "https://www.alphavantage.co/query?function=SECTOR&apikey=test" path_file = self.get_file_from_url("mock_sector") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -179,7 +179,7 @@ def test_foreign_exchange(self, mock_request): """ Test that api call returns a json file as requested """ fe = ForeignExchange(key=TestAlphaVantage._API_KEY_TEST) - url = "http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=CNY&apikey=test" + url = "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=CNY&apikey=test" path_file = self.get_file_from_url("mock_foreign_exchange") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -193,7 +193,7 @@ def test_batch_quotes(self, mock_request): """ Test that api call returns a json file as requested """ ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST) - url = "http://www.alphavantage.co/query?function=BATCH_STOCK_QUOTES&symbols=MSFT,FB,AAPL&apikey=test" + url = "https://www.alphavantage.co/query?function=BATCH_STOCK_QUOTES&symbols=MSFT,FB,AAPL&apikey=test" path_file = self.get_file_from_url("mock_batch_quotes") with open(path_file) as f: mock_request.get(url, text=f.read()) @@ -207,7 +207,7 @@ def test_batch_quotes_pandas(self, mock_request): """ ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST, output_format='pandas') - url = "http://www.alphavantage.co/query?function=BATCH_STOCK_QUOTES&symbols=MSFT,FB,AAPL&apikey=test&datatype=json" + url = "https://www.alphavantage.co/query?function=BATCH_STOCK_QUOTES&symbols=MSFT,FB,AAPL&apikey=test&datatype=json" path_file = self.get_file_from_url("mock_batch_quotes") with open(path_file) as f: mock_request.get(url, text=f.read()) From 5d3d1694a1c1d99a23c053eeb8bd7d0655909614 Mon Sep 17 00:00:00 2001 From: Filipe Filardi Date: Fri, 11 Oct 2019 23:18:40 -0300 Subject: [PATCH 2/8] Fix comment in daily function --- alpha_vantage/timeseries.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alpha_vantage/timeseries.py b/alpha_vantage/timeseries.py index bf0ecb4..a22642f 100644 --- a/alpha_vantage/timeseries.py +++ b/alpha_vantage/timeseries.py @@ -34,7 +34,7 @@ def get_daily(self, symbol, outputsize='compact'): 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 intraday times + data series, and 'full' returns the full-length daily times series, commonly above 1MB (default 'compact') """ _FUNCTION_KEY = "TIME_SERIES_DAILY" @@ -52,7 +52,7 @@ def get_daily_adjusted(self, symbol, outputsize='compact'): 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 intraday times + data series, and 'full' returns the full-length daily times series, commonly above 1MB (default 'compact') """ _FUNCTION_KEY = "TIME_SERIES_DAILY_ADJUSTED" From 0f468a28f51f15a317f807a8d8601736f71e410d Mon Sep 17 00:00:00 2001 From: daHIFI Date: Sat, 19 Oct 2019 21:10:06 -0400 Subject: [PATCH 3/8] ValueError for empty dict response from API https://github.com/RomelTorres/alpha_vantage/issues/154 --- alpha_vantage/alphavantage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/alpha_vantage/alphavantage.py b/alpha_vantage/alphavantage.py index 67c7481..d641c8e 100644 --- a/alpha_vantage/alphavantage.py +++ b/alpha_vantage/alphavantage.py @@ -162,6 +162,7 @@ def _format_wrapper(self, *args, **kwargs): if 'json' in self.output_format.lower() or 'pandas' \ in self.output_format.lower(): data = call_response[data_key] + if meta_data_key is not None: meta_data = call_response[meta_data_key] else: @@ -271,7 +272,10 @@ def _handle_api_call(self, url): if 'json' in self.output_format.lower() or 'pandas' in \ self.output_format.lower(): json_response = response.json() - if "Error Message" in json_response: + if not json_response: + raise ValueError( + 'Error getting data from the api, no return was given.') + elif "Error Message" in json_response: raise ValueError(json_response["Error Message"]) elif "Information" in json_response and self.treat_info_as_error: raise ValueError(json_response["Information"]) From 6fd20aee69b0fb73565525b191891943df677ee1 Mon Sep 17 00:00:00 2001 From: Patrick Collins <54278053+PatrickAlphaVantage@users.noreply.github.com> Date: Fri, 25 Oct 2019 09:41:40 -0400 Subject: [PATCH 4/8] Added slack, twitter, and email contact channels. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d09df14..a859c86 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,15 @@ Contributing is always welcome, since sometimes I am busy. Just contact me on ho * Add test for csv calls as well. * Add tests for incompatible parameter raise errors. + + +## Contact: +You can reach the Alpha Vantage team on any of the following platforms: +[Slack](https://alphavantage.herokuapp.com/) +[Twitter: @alpha_vantage](https://alphavantage.herokuapp.com/) +Email: support@alphavantage.co + + ## Star if you like it. If you like or use this project, consider showing your support by starring it. From 0ea292e0b26f26d0e5b546fc122d2d7459cd08c8 Mon Sep 17 00:00:00 2001 From: Patrick Collins <54278053+PatrickAlphaVantage@users.noreply.github.com> Date: Fri, 25 Oct 2019 09:43:10 -0400 Subject: [PATCH 5/8] Fixed spacing of contact information --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a859c86..7675365 100644 --- a/README.md +++ b/README.md @@ -204,9 +204,9 @@ Contributing is always welcome, since sometimes I am busy. Just contact me on ho ## Contact: You can reach the Alpha Vantage team on any of the following platforms: -[Slack](https://alphavantage.herokuapp.com/) -[Twitter: @alpha_vantage](https://alphavantage.herokuapp.com/) -Email: support@alphavantage.co +* [Slack](https://alphavantage.herokuapp.com/) +* [Twitter: @alpha_vantage](https://alphavantage.herokuapp.com/) +* Email: support@alphavantage.co ## Star if you like it. From 0ed8b0cc37c2488a9caf35f9b6c598a5518278e7 Mon Sep 17 00:00:00 2001 From: Patrick Collins <54278053+PatrickAlphaVantage@users.noreply.github.com> Date: Fri, 25 Oct 2019 09:44:04 -0400 Subject: [PATCH 6/8] Updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7675365..288b14e 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Contributing is always welcome, since sometimes I am busy. Just contact me on ho ## Contact: You can reach the Alpha Vantage team on any of the following platforms: * [Slack](https://alphavantage.herokuapp.com/) -* [Twitter: @alpha_vantage](https://alphavantage.herokuapp.com/) +* [Twitter: @alpha_vantage](https://twitter.com/alpha_vantage) * Email: support@alphavantage.co From 8817bebed99fd49f66a1fb2db21e8c57ed60b11c Mon Sep 17 00:00:00 2001 From: PatrickAlphaVantage Date: Thu, 31 Oct 2019 17:16:56 -0400 Subject: [PATCH 7/8] Added VWAP --- alpha_vantage/techindicators.py | 14 ++++++++++++++ docs/conf.py | 6 +++--- setup.py | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/alpha_vantage/techindicators.py b/alpha_vantage/techindicators.py index 93e5c67..f6508a3 100644 --- a/alpha_vantage/techindicators.py +++ b/alpha_vantage/techindicators.py @@ -163,6 +163,20 @@ def get_mama(self, symbol, interval='daily', series_type='close', _FUNCTION_KEY = "MAMA" return _FUNCTION_KEY, 'Technical Analysis: MAMA', 'Meta Data' + @av._output_format + @av._call_api_on_func + def get_vwap(self, symbol, interval='5min'): + """ Returns the volume weighted average price (VWAP) for intraday time series. + + 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 5min) + """ + _FUNCTION_KEY = "VWAP" + return _FUNCTION_KEY, 'Technical Analysis: VWAP', 'Meta Data' + @av._output_format @av._call_api_on_func def get_t3(self, symbol, interval='daily', time_period=20, series_type='close'): diff --git a/docs/conf.py b/docs/conf.py index a1547e7..c3eaaf7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = u'2.1.0' +version = u'2.1.1' # The full version, including alpha/beta/rc tags. -release = u'2.1.0' +release = u'2.1.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -153,6 +153,6 @@ 'Miscellaneous'), ] -#-- Napoleon options +# -- Napoleon options napoleon_include_private_with_doc = True diff --git a/setup.py b/setup.py index 36a1f15..b835741 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='alpha_vantage', - version='2.1.0', + version='2.1.1', author='Romel J. Torres', author_email='romel.torres@gmail.com', license='MIT', From c062f0881f01a9abc8efd5b204d8401d4aab8094 Mon Sep 17 00:00:00 2001 From: PatrickAlphaVantage Date: Fri, 8 Nov 2019 12:58:00 -0500 Subject: [PATCH 8/8] prep for 2.1.2 --- docs/conf.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c3eaaf7..51fa804 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = u'2.1.1' +version = u'2.1.2' # The full version, including alpha/beta/rc tags. -release = u'2.1.1' +release = u'2.1.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index b835741..0587528 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='alpha_vantage', - version='2.1.1', + version='2.1.2', author='Romel J. Torres', author_email='romel.torres@gmail.com', license='MIT',