diff --git a/README.md b/README.md index d09df14..288b14e 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://twitter.com/alpha_vantage) +* Email: support@alphavantage.co + + ## Star if you like it. If you like or use this project, consider showing your support by starring it. diff --git a/alpha_vantage/alphavantage.py b/alpha_vantage/alphavantage.py index 67c7481..2815dbd 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 = \ @@ -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"]) 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/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" diff --git a/docs/conf.py b/docs/conf.py index a1547e7..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.0' +version = u'2.1.2' # The full version, including alpha/beta/rc tags. -release = u'2.1.0' +release = u'2.1.2' # 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..0587528 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='alpha_vantage', - version='2.1.0', + version='2.1.2', author='Romel J. Torres', author_email='romel.torres@gmail.com', license='MIT', 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())