Implement start_date in databento.fetch_daily_ohlc (was silently dead)#30
Merged
Merged
Conversation
Every code path ignored it: a cold cache always backfilled from 2000-01-01 (clamped to the GLBX.MDP3 floor 2010-06-06), and a warm cache always resumed from last_date+1, regardless of what was passed. A caller trying to bound a fetch (e.g. 'just the last 3 months') silently got a full-history pull instead, at full Databento API cost, with no error or warning. Checked every caller before deciding how to fix it. grep across the workspace shows no one relies on it working: the function's only real internal caller (update_all_daily_prices) never passes it, both tests never pass it, and every OTHER fetch_daily_ohlc in the tree (npf.ml.labels) is an unrelated function that correctly forwards its own start_date into cotdata.get_prices — not this one. Removed rather than wired in. An explicit TypeError for a future caller beats another silent full-history surprise, and there is no current caller to write a correctness test against if the parameter were implemented instead. A genuinely bounded fetch, if ever needed, should be a new function with its own test proving the bound is honored. Found while building a bounded, one-off Databento divergence-check script in livebook, which deliberately avoided reusing this function for exactly this reason. 81 tests pass (5 apparent failures in test_norgate_provider.py are pre-existing and environment-dependent — COTDATA_STORE unset — confirmed via git stash, unrelated to this change). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Correctly pointed out that removal just relocates the problem — a future caller (including my own livebook divergence-check script, which had to write a separate bounded fetch specifically because this function couldn't do it) still needs a bounded fetch, and the test infrastructure to verify it correctly already exists in this file (the mock Historical client pattern). Cold cache (symbol's first-ever fetch): start_date now narrows the fetch floor (still clamped to the GLBX.MDP3 2010-06-06 floor), so a narrow first-time query is actually cheap — this is the real fix for the original API-cost bug. Warm cache (symbol already has history): start_date deliberately does NOT narrow the incremental fetch, which always resumes from the cache's own last_date+1. The cache is a single shared, from-inception series across every caller; letting a later, narrower start_date shrink what gets fetched would silently truncate a cache other callers rely on being complete. start_date still filters what's RETURNED in this case, just not what's fetched or persisted to disk. Both branches are tested against the mock Historical client, including the warm-cache case specifically (pre-seeded 3-day cache, narrower start_date requested, asserts the fetch call still starts from last_date+1 while the returned frame excludes the pre-start row AND the on-disk cache keeps the full series). 6 new tests, 8/8 in this file, 86/86 full suite (COTDATA_STORE set). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fetch_daily_ohlc'sstart_dateparameter was never used on any code path: a cold cache always backfilled from 2000-01-01 (clamped to the GLBX.MDP3 floor 2010-06-06), and a warm cache always resumed fromlast_date + 1 day, regardless of what was passed. A caller trying to bound a fetch got a silent full-history pull at full Databento API cost instead.start_datenow narrows the fetch floor (still clamped to the GLBX.MDP3 floor), so a narrow first-time query is actually cheap -- this is the real fix for the cost bug.start_datedoes not narrow the incremental fetch, which always resumes from the cache's ownlast_date + 1. The cache is a single shared, from-inception series across every caller; letting a later, narrowerstart_dateshrink what gets fetched would silently truncate a cache other callers rely on being complete.start_datestill filters what's returned in this case, just not what's fetched or persisted to disk.update_all_daily_prices) never passesstart_date, neither existing test passes it, and the otherfetch_daily_ohlcin the tree (npf.ml.labels) is an unrelated function that correctly forwards its ownstart_dateintocotdata.get_prices-- not this one.Found while building a bounded, one-off Databento divergence-check script in a sibling repo (
livebook), which had to write its own bounded fetch specifically because this function couldn't do it.Test plan
pytest tests/test_databento_provider.py-- 8 passed (2 existing + 6 new covering: cold-cache floor narrowing, GLBX-floor clamping still applies, return-value filtering, theNonedefault is unchanged, and the warm-cache case -- pre-seeded 3-day cache, narrowerstart_daterequested, asserts the fetch call still starts fromlast_date+1while the returned frame excludes the pre-start row and the on-disk cache keeps the full series)pytest tests/(full suite,COTDATA_STOREset) -- 86 passedtest_norgate_provider.pyfailures seen withoutCOTDATA_STOREset are pre-existing and unrelated (reproduced identically with this changegit stashed out)grep -rn "fetch_daily_ohlc("across the workspace -- no current caller passesstart_dateto this function, so this is purely additive🤖 Generated with Claude Code