Yahoo: keep padding the end timestamp but ignore any extra day returned.

This commit is contained in:
Chris Berkhout 2023-06-10 13:21:40 +02:00
parent 34c503f6cb
commit b7b2862b77
2 changed files with 10 additions and 2 deletions

View file

@ -140,7 +140,7 @@ class Yahoo(BaseSource):
.timestamp() .timestamp()
) + ( ) + (
24 * 60 * 60 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_url = f"{base_url}/download/{series.base}"
history_params = { history_params = {
@ -191,4 +191,6 @@ class Yahoo(BaseSource):
if history_lines[0] != "date,open,high,low,close,adjclose,volume": if history_lines[0] != "date,open,high,low,close,adjclose,volume":
raise exceptions.ResponseParsingError("Unexpected CSV format") 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)

View file

@ -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")) 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): def test_fetch_requests_logged(src, type, spark_ok, recent_ok, caplog):
with caplog.at_level(logging.DEBUG): with caplog.at_level(logging.DEBUG):
src.fetch(Series("TSLA", "", type, "2021-01-04", "2021-01-08")) src.fetch(Series("TSLA", "", type, "2021-01-04", "2021-01-08"))