Files
fxhnt/tests/unit/test_ibkr_volume_pit.py
jgrusewski ee8694dffb feat(equity): IBKR pit-volume store + historical_daily_volume + ucits_volume_source flag
Task 1 of the IBKR UCITS volume source plan: adds ibkr_pit_volume (first-seen-
frozen, mirrors yahoo_pit_volume), IbkrBroker.historical_daily_volume
(reqHistoricalData TRADES, integration-only, never raises), and the
ucits_volume_source config flag (default yahoo, additive ibkr path). Task 2
(CLI + provider read) and Task 3 (CronJob) are separate follow-ons.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-16 12:42:59 +02:00

29 lines
1.2 KiB
Python

"""ibkr_pit_volume storage (mirrors test_yahoo_volume_pit.py) + ucits_volume_source config flag.
NOTE: `IbkrBroker.historical_daily_volume` needs a live ib-gateway connection (reqHistoricalData over the
wire) — it is integration-only and is NOT unit-tested here. This file covers the storage layer (PIT
first-seen-frozen roundtrip) and the config flag only.
"""
import datetime as dt
from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
from fxhnt.config import AllocationSettings
def test_snapshot_and_read_ibkr_volumes_first_seen_frozen():
r = ForwardNavRepo("sqlite://")
r.migrate()
at = dt.datetime(2026, 7, 16)
r.snapshot_ibkr_volumes("CSPX.L", {"2026-07-01": 1000.0, "2026-07-02": 2000.0}, at)
r.snapshot_ibkr_volumes("CSPX.L", {"2026-07-01": 9999.0, "2026-07-03": 3000.0}, at) # 07-01 must NOT change
assert r.ibkr_pit_volumes("CSPX.L") == {"2026-07-01": 1000.0, "2026-07-02": 2000.0, "2026-07-03": 3000.0}
def test_ucits_volume_source_default_yahoo():
assert AllocationSettings().ucits_volume_source == "yahoo"
def test_ucits_volume_source_env_override(monkeypatch):
monkeypatch.setenv("FXHNT_ALLOCATION_UCITS_VOLUME_SOURCE", "ibkr")
assert AllocationSettings().ucits_volume_source == "ibkr"