trader.marketdata.cache module¶
Bar cache: fetch a window once, reuse it thereafter.
Backtests re-read the same history repeatedly. Fetching every time is slow, rate-limited, and — because Yahoo revises history — makes results drift for reasons unrelated to the code under test.
- class trader.marketdata.cache.BarCache(repository, provider, refresh_tail=None)[source]¶
Bases:
objectEnsures a date window is present locally, fetching only what is missing.
- Parameters:
repository (BarRepository)
provider (MarketDataProvider)
refresh_tail (timedelta | None)
- __init__(repository, provider, refresh_tail=None)[source]¶
- Parameters:
refresh_tail (timedelta | None) –
how far back from a requested window’s end to re-fetch on every call. None keeps the cache strictly fetch-once, which is what backtests want. The trading path sets it, because the current day’s bar is written partial — its high, low and close are wherever price stood at the first fetch of the day — and save_bars skips timestamps it already holds, so nothing would ever correct it to the real close.
The policy lives here rather than at each call site so a second caller cannot forget it.
repository (BarRepository)
provider (MarketDataProvider)
- Return type:
None