Files
fxhnt/tests/unit/test_yahoo_volume_pit.py
2026-07-16 10:23:09 +02:00

24 lines
1017 B
Python

import datetime as dt
from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
def test_snapshot_and_read_volumes_first_seen_frozen():
r = ForwardNavRepo("sqlite://")
r.migrate()
at = dt.datetime(2026, 7, 16)
r.snapshot_yahoo_volumes("SPY", {"2026-07-01": 1000.0, "2026-07-02": 2000.0}, at)
r.snapshot_yahoo_volumes("SPY", {"2026-07-01": 9999.0, "2026-07-03": 3000.0}, at) # 07-01 must NOT change
assert r.yahoo_pit_volumes("SPY") == {"2026-07-01": 1000.0, "2026-07-02": 2000.0, "2026-07-03": 3000.0}
def test_volumes_extracts_quote_volume(monkeypatch):
from fxhnt.adapters.data.yahoo_daily import YahooDailyClient
c = YahooDailyClient()
fake = {"chart": {"result": [{"timestamp": [1719792000, 1719878400],
"indicators": {"quote": [{"volume": [111.0, None]}], "adjclose": [{"adjclose": [1.0, 2.0]}]}}]}}
monkeypatch.setattr(c, "_get", lambda url: fake)
out = c.volumes("SPY")
assert list(out.values()) == [111.0] # None volume day skipped