Fetch prices with batched Yahoo quotes (#13) #53

Merged
chris-kreidl merged 1 commit from 13-batched-quotes into main 2026-11-12 13:33:29 +00:00
chris-kreidl commented 2026-11-12 13:19:55 +00:00 (Migrated from github.com)

🤖 Claude: Closes #13

Enrich now prices companies with quote() calls of up to 100 symbols. It used to make one quoteSummary call per company, one per second. Sectors still come from #14's sector_cache. The only quoteSummary call left is the summaryProfile lookup on a cache miss.

Changes

  • src/enrich.ts
    • All prices are fetched first (16 batches today), then sector lookups run for cache misses, then every row is written in one transaction. A failed quote request throws before anything is written, so it can't clear 100 prices or leave a half-updated table. The old loop treated a failed request as "no quote" and cleared that company's price.
    • quote() runs with validateResult: false and only the two fields we need. Otherwise one symbol failing the library's schema would throw away its whole batch. Both fields are checked by hand instead.
    • Network access goes through a Market interface (yahooMarket in production). This is what makes enrich testable without network access.
    • estimatedSeconds() replaces SECONDS_PER_REQUEST: one request per batch plus one per cache miss.
  • cli.ts: the enrich hint uses the new estimate.
  • test/enrich.test.ts (new): enrich had no tests before.
  • CLAUDE.md: the enrich step's description is updated.

Acceptance criteria (revised, from the comment on #13)

  • Prices and market caps from quote(), in batches of up to 100. Tested: 250 tickers → batches of [100, 100, 50].
  • Sector and industry from #14's cache; no quoteSummary calls of this story's own. Tested: a cached company gets no profile lookup, and the SIC fallback still works. Real run: 0 profile lookups.
  • No quote or no ticker still clears the old price (#5). Tested. A ticker with no quote is kept, as before.
  • Only Yahoo's market cap, no fallback (#40). Tested: no market cap from Yahoo is stored as null.
  • A full re-price takes under 5 minutes. Real run: 17 s for 1,679 companies (1,593 tickers, warm cache). It was about 28 min before. Chris confirmed 5 minutes is an upper bound, not a target.
  • Parity on real data. Compared with the DB from the Nov 11 run, which used the per-company quoteSummary path:
    • Eligible companies: 1,679 in both.
    • Priced: 1,591 in both, the same companies. No company is priced in only one run.
    • With a market cap: 1,577 in both, the same companies.
    • Ticker or sector differences: none.
    • Ranked CSV: the same 1,391 companies, with no ticker, sector or industry changes.

One finding (not caused by this change): WAT's market cap went from $46.2B to $92.5B, and SUPN's from $1.7B to $6.1B, with the same price in both runs. I checked both endpoints today. quote() and quoteSummary's price module return the same new values (WAT 98.3M shares, $92.5B; SUPN 207.7M shares, $6.1B). Yahoo's data changed overnight; batching didn't cause it. SUPN moved from rank 33 to 366 because of it. Chris treats it as a transient glitch in Yahoo's data; no issue needed.

Definition of Done

  • Acceptance criteria met and demonstrated (above)
  • bun test passes; new logic has tests: 220 pass, 0 fail (7 new in test/enrich.test.ts)
  • bun check is clean and bun fmt --check passes: "No type errors in 28 files"; "All 4 files are formatted"
  • Runs end to end on real data (not just fixtures): bun cli.ts enrich → "1591 priced (8 sectors from SEC SIC codes) · 0 profile lookups · 86 no ticker · 2 no quote", done in 17 s. bun cli.ts rank → top 10 of 1,391.
  • Stand-up posted on the milestone tracking issue when the story started and when this PR opened (#50)

🤖 Generated with Claude Code

🤖 **Claude:** Closes #13 Enrich now prices companies with `quote()` calls of up to 100 symbols. It used to make one `quoteSummary` call per company, one per second. Sectors still come from #14's `sector_cache`. The only `quoteSummary` call left is the `summaryProfile` lookup on a cache miss. ### Changes - **`src/enrich.ts`** - All prices are fetched first (16 batches today), then sector lookups run for cache misses, then every row is written in **one transaction**. A failed quote request throws before anything is written, so it can't clear 100 prices or leave a half-updated table. The old loop treated a failed request as "no quote" and cleared that company's price. - `quote()` runs with `validateResult: false` and only the two fields we need. Otherwise one symbol failing the library's schema would throw away its whole batch. Both fields are checked by hand instead. - Network access goes through a `Market` interface (`yahooMarket` in production). This is what makes enrich testable without network access. - `estimatedSeconds()` replaces `SECONDS_PER_REQUEST`: one request per batch plus one per cache miss. - **`cli.ts`**: the enrich hint uses the new estimate. - **`test/enrich.test.ts`** (new): enrich had no tests before. - **`CLAUDE.md`**: the enrich step's description is updated. ### Acceptance criteria (revised, from the comment on #13) - [x] **Prices and market caps from `quote()`, in batches of up to 100.** Tested: 250 tickers → batches of `[100, 100, 50]`. - [x] **Sector and industry from #14's cache; no `quoteSummary` calls of this story's own.** Tested: a cached company gets no profile lookup, and the SIC fallback still works. Real run: 0 profile lookups. - [x] **No quote or no ticker still clears the old price (#5).** Tested. A ticker with no quote is kept, as before. - [x] **Only Yahoo's market cap, no fallback (#40).** Tested: no market cap from Yahoo is stored as null. - [x] **A full re-price takes under 5 minutes.** Real run: **17 s** for 1,679 companies (1,593 tickers, warm cache). It was about 28 min before. Chris confirmed 5 minutes is an upper bound, not a target. - [x] **Parity on real data.** Compared with the DB from the Nov 11 run, which used the per-company `quoteSummary` path: - Eligible companies: 1,679 in both. - Priced: **1,591 in both, the same companies.** No company is priced in only one run. - With a market cap: **1,577 in both, the same companies.** - Ticker or sector differences: **none.** - Ranked CSV: **the same 1,391 companies**, with no ticker, sector or industry changes. **One finding (not caused by this change):** WAT's market cap went from $46.2B to $92.5B, and SUPN's from $1.7B to $6.1B, with the same price in both runs. I checked both endpoints today. `quote()` and `quoteSummary`'s `price` module return the **same** new values (WAT 98.3M shares, $92.5B; SUPN 207.7M shares, $6.1B). Yahoo's data changed overnight; batching didn't cause it. SUPN moved from rank 33 to 366 because of it. Chris treats it as a transient glitch in Yahoo's data; no issue needed. ### Definition of Done - [x] Acceptance criteria met and demonstrated (above) - [x] `bun test` passes; new logic has tests: 220 pass, 0 fail (7 new in `test/enrich.test.ts`) - [x] `bun check` is clean and `bun fmt --check` passes: "No type errors in 28 files"; "All 4 files are formatted" - [x] Runs end to end on real data (not just fixtures): `bun cli.ts enrich` → "1591 priced (8 sectors from SEC SIC codes) · 0 profile lookups · 86 no ticker · 2 no quote", done in 17 s. `bun cli.ts rank` → top 10 of 1,391. - [x] Stand-up posted on the milestone tracking issue when the story started and when this PR opened (#50) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No milestone
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!53
No description provided.