From 2b0f01110ab28e6c05e5bd083679b82680c803e9 Mon Sep 17 00:00:00 2001 From: Chris Berkhout Date: Sat, 26 Aug 2023 10:50:41 +0200 Subject: [PATCH] Revert "Update Alphavantage source for changes in which endpoint is premium." This reverts commit d6036c9d148b79b3fac39c0ba5c713dd88497c8b. --- src/pricehist/sources/alphavantage.py | 12 +++++++----- tests/live.sh | 10 +++++----- tests/pricehist/sources/test_alphavantage.py | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/pricehist/sources/alphavantage.py b/src/pricehist/sources/alphavantage.py index 4824282..707ba50 100644 --- a/src/pricehist/sources/alphavantage.py +++ b/src/pricehist/sources/alphavantage.py @@ -51,7 +51,8 @@ class AlphaVantage(BaseSource): "will list all digital and physical currency symbols.\n" "The PAIR for stocks is the stock symbol only. The quote currency " f"will be determined automatically. {self._stock_symbols_message()}\n" - "The price type 'adjclose' is only available for stocks.\n" + "The price type 'adjclose' is only available for stocks, and " + "requires an access key for which premium endpoints are unlocked.\n" "Beware that digital currencies quoted in non-USD currencies may " "be converted from USD data at one recent exchange rate rather " "than using historical rates.\n" @@ -186,9 +187,10 @@ class AlphaVantage(BaseSource): def _stock_data(self, series): output_quote = self._stock_currency(series.base) or "UNKNOWN" - # As of 2022-11-24 TIME_SERIES_DAILY_ADJUSTED is no longer premium, but - # now TIME_SERIES_DAILY is. So, always use TIME_SERIES_DAILY_ADJUSTED. - function = "TIME_SERIES_DAILY_ADJUSTED" + if series.type == "adjclose": + function = "TIME_SERIES_DAILY_ADJUSTED" + else: + function = "TIME_SERIES_DAILY" params = { "function": function, @@ -339,7 +341,7 @@ class AlphaVantage(BaseSource): raise exceptions.RateLimit(data["Note"]) if ( "Information" in data - and "unlock all premium endpoints" in data["Information"] + and "ways to unlock premium" in data["Information"] ): msg = "You were denied access to a premium endpoint." raise exceptions.CredentialsError([self.API_KEY_NAME], self, msg) diff --git a/tests/live.sh b/tests/live.sh index 2fd2b09..78da3c0 100755 --- a/tests/live.sh +++ b/tests/live.sh @@ -63,11 +63,11 @@ name="Alpha Vantage stocks" cmd="pricehist fetch alphavantage TSLA -s 2021-01-04 -e 2021-01-08" read -r -d '' expected <