Refresh incrementally from SEC's daily form index (#12) #54
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
epic:E1-foundation
epic:E2-correct-metrics
epic:E3-fast-jobs
epic:E4-cli
epic:E5-web-ui
epic:E6-history
good first issue
help wanted
invalid
question
sprint-tracking
story
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ckreidl/screener!54
Loading…
Reference in a new issue
No description provided.
Delete branch "12-incremental-refresh"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
🤖 Claude: Closes #12
bun cli.ts refreshnow updatesdata/from SEC's daily form index instead of downloading the ~1 GB zip each time.How it works
daily-index/<year>/QTR<n>/index.jsonlists theform.<yyyymmdd>.idxfiles that exist, so weekends, holidays, and today's unpublished index are simply absent. A request for a missing file returns 403, the same status SEC uses for rate-limit blocks, so guessing from errors would be ambiguous.10-Krows count (not10-K/Aor10-KT), since those are the only filingsanalyzereads. Each filing CIK'scompanyfactsis downloaded and replaces its file in place (written to a temp file, then renamed).pending_10kand is retried on the next refresh. A 404 (no companyfacts for that company yet) is pending too.refresh_staterow or nodata/), with--full, or when the last covered day is more than 30 days old. Coverage is set to the day before the zip'sLast-Modifieddate (New York time), so the next refresh re-reads the day the zip was built.refresh_stateandpending_10k, both created byensureSchema. It is written in one transaction at the end, so a failed run leaves state unchanged and the next run repeats the same days.secFetchinsrc/sec.tssendsSEC_HEADERSand paces all calls to at most 5 starts per second, with up to 5 downloads in flight. Any HTTP error other than 404 stops the refresh immediately rather than continuing to hit SEC.--full, the refresh hint shows coverage and the pending count, and the summary lists pending and expired 10-Ks.Decision for you
A 10-K that never shows up in SEC's API (for example, a filer with no XBRL) would otherwise be retried forever. I drop it after the same 30 days and list it as expired. Say if you'd rather handle that differently.
Demonstrated on real data
I copied yesterday's
data/to a separate folder. It came from the bulk zip SEC built the night of 11-10, so it covers filings through 11-09. In a second folder I ran a--fullrefresh today.--fulltodaycompany_analysis: all 5,456 rows match on every analysis column (0 differences).rank: I enriched once and copied the price and sector columns into the other database, since live prices drift between runs. Both produced byte-identical CSVs, each ranking 1,388 companies.Definition of Done
bun testpasses; new logic has tests: 236 pass.test/refresh.test.tshas 15 tests covering each criterion, plus a CLI test for--fullbun checkis clean andbun fmt --checkpasses🤖 Generated with Claude Code
Code review
No issues found. Checked for bugs and CLAUDE.md compliance.