Skip to content

Commit

Permalink
Merge pull request #163 from RomelTorres/develop
Browse files Browse the repository at this point in the history
Prep for 2.1.2
  • Loading branch information
PatrickAlphaC committed Nov 8, 2019
2 parents fabbb45 + 295aa95 commit c6fab0f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 19 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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.

Expand Down
8 changes: 6 additions & 2 deletions alpha_vantage/alphavantage.py
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"])
Expand Down
14 changes: 14 additions & 0 deletions alpha_vantage/techindicators.py
Expand Up @@ -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'):
Expand Down
4 changes: 2 additions & 2 deletions alpha_vantage/timeseries.py
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Expand Up @@ -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.
Expand Down Expand Up @@ -153,6 +153,6 @@
'Miscellaneous'),
]

#-- Napoleon options
# -- Napoleon options

napoleon_include_private_with_doc = True
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down
22 changes: 11 additions & 11 deletions test_alpha_vantage/test_alphavantage.py
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down

0 comments on commit c6fab0f

Please sign in to comment.