Incremental SEC update via the EDGAR daily index #12

Closed
opened 2026-11-06 01:19:10 +00:00 by chris-kreidl · 1 comment
chris-kreidl commented 2026-11-06 01:19:10 +00:00 (Migrated from github.com)

Re-fetch only companies that filed (/api/xbrl/companyfacts/CIK##########.json) instead of the ~1 GB bulk zip.

Acceptance criteria

Accepted by Chris on 2026-11-12. Decisions: 30-day gap limit, state kept in SQLite, 5 requests/second.

  • bun cli.ts refresh reads SEC's daily index (Archives/edgar/daily-index/<year>/QTR<n>/form.<yyyymmdd>.idx) for every business day since the last successful refresh, and re-downloads api/xbrl/companyfacts/CIK##########.json only for CIKs that filed a 10-K. Each file is written to data/ in place.
  • A day with no index file (weekend, holiday) is skipped, not an error.
  • Catches SEC's lag: a 10-K is done only when the downloaded companyfacts contains that filing's accession number. Otherwise it stays pending and is retried on the next refresh.
  • The bulk zip is used, as today, on the first run (no data/ or no record of a refresh), with refresh --full, and when the last successful refresh was more than 30 days ago.
  • The last successful refresh and the pending 10-Ks are stored in SQLite (company_facts.db), in a table owned by ensureSchema.
  • SEC fair-access rules are respected: at most 5 requests/second (SEC's cap is 10), with the existing SEC_HEADERS.
  • Demonstrated on real data:
    • a refresh one day after a full one finishes in minutes and lists how many 10-Ks it fetched;
    • analyze + rank after it agree with a --full refresh on the same day, except for filings still pending, which are listed.

Definition of Done

  • Acceptance criteria met and demonstrated
  • bun test passes; new logic has tests
  • bun check is clean and bun fmt --check passes
  • Runs end to end on real data (not just fixtures)
  • Committed with Closes #<this issue>
Re-fetch only companies that filed (`/api/xbrl/companyfacts/CIK##########.json`) instead of the ~1 GB bulk zip. ### Acceptance criteria *Accepted by Chris on 2026-11-12. Decisions: 30-day gap limit, state kept in SQLite, 5 requests/second.* - [ ] `bun cli.ts refresh` reads SEC's daily index (`Archives/edgar/daily-index/<year>/QTR<n>/form.<yyyymmdd>.idx`) for every business day since the last successful refresh, and re-downloads `api/xbrl/companyfacts/CIK##########.json` only for CIKs that filed a `10-K`. Each file is written to `data/` in place. - [ ] A day with no index file (weekend, holiday) is skipped, not an error. - [ ] **Catches SEC's lag:** a 10-K is done only when the downloaded companyfacts contains that filing's accession number. Otherwise it stays pending and is retried on the next refresh. - [ ] The bulk zip is used, as today, on the first run (no `data/` or no record of a refresh), with `refresh --full`, and when the last successful refresh was more than **30 days** ago. - [ ] The last successful refresh and the pending 10-Ks are stored in SQLite (`company_facts.db`), in a table owned by `ensureSchema`. - [ ] SEC fair-access rules are respected: at most **5 requests/second** (SEC's cap is 10), with the existing `SEC_HEADERS`. - [ ] Demonstrated on real data: - a refresh one day after a full one finishes in minutes and lists how many 10-Ks it fetched; - `analyze` + `rank` after it agree with a `--full` refresh on the same day, except for filings still pending, which are listed. ### Definition of Done - [ ] Acceptance criteria met and demonstrated - [ ] `bun test` passes; new logic has tests - [ ] `bun check` is clean and `bun fmt --check` passes - [ ] Runs end to end on real data (not just fixtures) - [ ] Committed with `Closes #<this issue>`
chris-kreidl commented 2026-11-11 20:24:47 +00:00 (Migrated from github.com)

🤖 Claude: Proposed acceptance criteria (backlog refinement; Chris to accept or change)

Today: refresh downloads the full companyfacts zip (~1 GB), and analyze reads only 10-K facts (src/extract.ts). So the only filings that can change our numbers are new 10-Ks.

Acceptance criteria

  • bun cli.ts refresh reads SEC's daily index (Archives/edgar/daily-index/<year>/QTR<n>/form.<yyyymmdd>.idx) for every business day since the last successful refresh, and re-downloads api/xbrl/companyfacts/CIK##########.json only for CIKs that filed a 10-K. Each file is written to data/ in place.
  • A day with no index file (weekend, holiday) is skipped, not an error.
  • Catches SEC's lag: a 10-K is done only when the downloaded companyfacts contains that filing's accession number. Otherwise it stays pending and is retried on the next refresh. (SEC can publish the index before its XBRL API has the facts.)
  • The first run (no data/ or no record of a refresh) uses the bulk zip, as today, and so does refresh --full.
  • SEC fair-access rules are respected: at most 10 requests/second, with the existing SEC_HEADERS.
  • Demonstrated on real data:
    • a refresh one day after a full one finishes in minutes and lists how many 10-Ks it fetched;
    • analyze + rank after it agree with a --full refresh on the same day, except for filings still pending, which are listed.

Questions

  1. Gap limit: if refresh hasn't run for a long time, walking every daily index gets slow. Fall back to the bulk zip after 30 days? Pick another number, or never fall back?
  2. Where does "last successful refresh" live? I'd put it in SQLite, which #15's job history would later use, instead of a marker file in data/. Fine?

Dependencies

None. Suggested order for M2: #14 → #13 → #12 → #15 (see #50).

🤖 **Claude:** **Proposed acceptance criteria** (backlog refinement; Chris to accept or change) **Today:** `refresh` downloads the full companyfacts zip (~1 GB), and `analyze` reads only `10-K` facts (`src/extract.ts`). So the only filings that can change our numbers are new 10-Ks. ### Acceptance criteria - [ ] `bun cli.ts refresh` reads SEC's daily index (`Archives/edgar/daily-index/<year>/QTR<n>/form.<yyyymmdd>.idx`) for every business day since the last successful refresh, and re-downloads `api/xbrl/companyfacts/CIK##########.json` only for CIKs that filed a `10-K`. Each file is written to `data/` in place. - [ ] A day with no index file (weekend, holiday) is skipped, not an error. - [ ] **Catches SEC's lag:** a 10-K is done only when the downloaded companyfacts contains that filing's accession number. Otherwise it stays pending and is retried on the next refresh. (SEC can publish the index before its XBRL API has the facts.) - [ ] The first run (no `data/` or no record of a refresh) uses the bulk zip, as today, and so does `refresh --full`. - [ ] SEC fair-access rules are respected: at most 10 requests/second, with the existing `SEC_HEADERS`. - [ ] Demonstrated on real data: - a refresh one day after a full one finishes in minutes and lists how many 10-Ks it fetched; - `analyze` + `rank` after it agree with a `--full` refresh on the same day, except for filings still pending, which are listed. ### Questions 1. **Gap limit:** if refresh hasn't run for a long time, walking every daily index gets slow. Fall back to the bulk zip after **30 days**? Pick another number, or never fall back? 2. Where does "last successful refresh" live? I'd put it in SQLite, which #15's job history would later use, instead of a marker file in `data/`. Fine? ### Dependencies None. Suggested order for M2: #14 → #13 → #12 → #15 (see #50).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/screener#12
No description provided.