From f4aee183603b92440177e83ad1dba2c196c460a4 Mon Sep 17 00:00:00 2001 From: Chris Berkhout Date: Thu, 11 Jul 2024 15:30:45 +0200 Subject: [PATCH] Update parsing of Alphavantage digital currency response data. --- src/pricehist/sources/alphavantage.py | 8 +- .../test_alphavantage/btc-aud-partial.json | 105 ++++++------------ 2 files changed, 39 insertions(+), 74 deletions(-) diff --git a/src/pricehist/sources/alphavantage.py b/src/pricehist/sources/alphavantage.py index ea80621..698add7 100644 --- a/src/pricehist/sources/alphavantage.py +++ b/src/pricehist/sources/alphavantage.py @@ -313,10 +313,10 @@ class AlphaVantage(BaseSource): normalized_data = { day: { - "open": entries[f"1a. open ({series.quote})"], - "high": entries[f"2a. high ({series.quote})"], - "low": entries[f"3a. low ({series.quote})"], - "close": entries[f"4a. close ({series.quote})"], + "open": entries[f"1. open"], + "high": entries[f"2. high"], + "low": entries[f"3. low"], + "close": entries[f"4. close"], } for day, entries in reversed( data["Time Series (Digital Currency Daily)"].items() diff --git a/tests/pricehist/sources/test_alphavantage/btc-aud-partial.json b/tests/pricehist/sources/test_alphavantage/btc-aud-partial.json index cd6412d..737658f 100644 --- a/tests/pricehist/sources/test_alphavantage/btc-aud-partial.json +++ b/tests/pricehist/sources/test_alphavantage/btc-aud-partial.json @@ -10,88 +10,53 @@ }, "Time Series (Digital Currency Daily)": { "2021-01-09": { - "1a. open (AUD)": "55074.06950240", - "1b. open (USD)": "40586.96000000", - "2a. high (AUD)": "56150.17720000", - "2b. high (USD)": "41380.00000000", - "3a. low (AUD)": "52540.71680000", - "3b. low (USD)": "38720.00000000", - "4a. close (AUD)": "54397.30924680", - "4b. close (USD)": "40088.22000000", - "5. volume": "75785.97967500", - "6. market cap (USD)": "75785.97967500" + "1. open": "55074.06950240", + "2. high": "56150.17720000", + "3. low": "52540.71680000", + "4. close": "54397.30924680", + "5. volume": "75785.97967500" }, "2021-01-08": { - "1a. open (AUD)": "53507.50941120", - "1b. open (USD)": "39432.48000000", - "2a. high (AUD)": "56923.63300000", - "2b. high (USD)": "41950.00000000", - "3a. low (AUD)": "49528.31000000", - "3b. low (USD)": "36500.00000000", - "4a. close (AUD)": "55068.43820140", - "4b. close (USD)": "40582.81000000", - "5. volume": "139789.95749900", - "6. market cap (USD)": "139789.95749900" + "1. open": "53507.50941120", + "2. high": "56923.63300000", + "3. low": "49528.31000000", + "4. close": "55068.43820140", + "5. volume": "139789.95749900" }, "2021-01-07": { - "1a. open (AUD)": "49893.81535840", - "1b. open (USD)": "36769.36000000", - "2a. high (AUD)": "54772.88310000", - "2b. high (USD)": "40365.00000000", - "3a. low (AUD)": "49256.92200000", - "3b. low (USD)": "36300.00000000", - "4a. close (AUD)": "53507.23802320", - "4b. close (USD)": "39432.28000000", - "5. volume": "132825.70043700", - "6. market cap (USD)": "132825.70043700" + "1. open": "49893.81535840", + "2. high": "54772.88310000", + "3. low": "49256.92200000", + "4. close": "53507.23802320", + "5. volume": "132825.70043700" }, "2021-01-06": { - "1a. open (AUD)": "46067.47523820", - "1b. open (USD)": "33949.53000000", - "2a. high (AUD)": "50124.29161740", - "2b. high (USD)": "36939.21000000", - "3a. low (AUD)": "45169.81872000", - "3b. low (USD)": "33288.00000000", - "4a. close (AUD)": "49893.81535840", - "4b. close (USD)": "36769.36000000", - "5. volume": "127139.20131000", - "6. market cap (USD)": "127139.20131000" + "1. open": "46067.47523820", + "2. high": "50124.29161740", + "3. low": "45169.81872000", + "4. close": "49893.81535840", + "5. volume": "127139.20131000" }, "2021-01-05": { - "1a. open (AUD)": "43408.17136500", - "1b. open (USD)": "31989.75000000", - "2a. high (AUD)": "46624.45840000", - "2b. high (USD)": "34360.00000000", - "3a. low (AUD)": "40572.50600000", - "3b. low (USD)": "29900.00000000", - "4a. close (AUD)": "46067.47523820", - "4b. close (USD)": "33949.53000000", - "5. volume": "116049.99703800", - "6. market cap (USD)": "116049.99703800" + "1. open": "43408.17136500", + "2. high": "46624.45840000", + "3. low": "40572.50600000", + "4. close": "46067.47523820", + "5. volume": "116049.99703800" }, "2021-01-04": { - "1a. open (AUD)": "44779.08784700", - "1b. open (USD)": "33000.05000000", - "2a. high (AUD)": "45593.18400000", - "2b. high (USD)": "33600.00000000", - "3a. low (AUD)": "38170.72220000", - "3b. low (USD)": "28130.00000000", - "4a. close (AUD)": "43406.76014740", - "4b. close (USD)": "31988.71000000", - "5. volume": "140899.88569000", - "6. market cap (USD)": "140899.88569000" + "1. open": "44779.08784700", + "2. high": "45593.18400000", + "3. low": "38170.72220000", + "4. close": "43406.76014740", + "5. volume": "140899.88569000" }, "2021-01-03": { - "1a. open (AUD)": "43661.51206300", - "1b. open (USD)": "32176.45000000", - "2a. high (AUD)": "47191.80858340", - "2b. high (USD)": "34778.11000000", - "3a. low (AUD)": "43371.85965060", - "3b. low (USD)": "31962.99000000", - "4a. close (AUD)": "44779.08784700", - "4b. close (USD)": "33000.05000000", - "5. volume": "120957.56675000", - "6. market cap (USD)": "120957.56675000" + "1. open": "43661.51206300", + "2. high": "47191.80858340", + "3. low": "43371.85965060", + "4. close": "44779.08784700", + "5. volume": "120957.56675000" } } }