diff --git a/src/pricehist/sources/yahoo.py b/src/pricehist/sources/yahoo.py index f93f53f..6997301 100644 --- a/src/pricehist/sources/yahoo.py +++ b/src/pricehist/sources/yahoo.py @@ -140,7 +140,7 @@ class Yahoo(BaseSource): .timestamp() ) + ( 24 * 60 * 60 - ) # round up to include the last day + ) # some symbols require padding on the end timestamp history_url = f"{base_url}/download/{series.base}" history_params = { @@ -191,4 +191,6 @@ class Yahoo(BaseSource): if history_lines[0] != "date,open,high,low,close,adjclose,volume": raise exceptions.ResponseParsingError("Unexpected CSV format") - return (quote, history) + requested_history = [row for row in history if row["date"] <= series.end] + + return (quote, requested_history) diff --git a/tests/pricehist/sources/test_yahoo.py b/tests/pricehist/sources/test_yahoo.py index e1954dc..ba1849b 100644 --- a/tests/pricehist/sources/test_yahoo.py +++ b/tests/pricehist/sources/test_yahoo.py @@ -126,6 +126,12 @@ def test_fetch_requests_and_receives_correct_times(src, type, spark_ok, recent_o assert series.prices[-1] == Price("2021-01-08", Decimal("880.020020")) +def test_fetch_ignores_any_extra_row(src, type, spark_ok, recent_ok): + series = src.fetch(Series("TSLA", "", type, "2021-01-04", "2021-01-07")) + assert series.prices[0] == Price("2021-01-04", Decimal("729.770020")) + assert series.prices[-1] == Price("2021-01-07", Decimal("816.039978")) + + def test_fetch_requests_logged(src, type, spark_ok, recent_ok, caplog): with caplog.at_level(logging.DEBUG): src.fetch(Series("TSLA", "", type, "2021-01-04", "2021-01-08"))