Skip to content

feat: historical support for the five remaining sources (#1802) - #1804

Merged
robcohen merged 2 commits into
mainfrom
feat/price-window-ports
Jul 18, 2026
Merged

robcohen merged 2 commits into
mainfrom
feat/price-window-ports

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

Ports the five remaining #1802 table rows onto the window primitive from #1803. After this, only coincap, coinmarketcap, and oanda remain latest-only (paid-tier / product-gap questions per the issue).

Source Historical mechanism Coverage
ecb SDMX data API startPeriod/endPeriod — the full EU-reference series, not just the 90-day XML feed the issue anticipated Since(1999-01-04)
alphavantage TIME_SERIES_DAILY (stock tickers; compact/full outputsize by window age). Forex/crypto ticker forms refuse hermetically before any network I/O, pointing at ratesapi/coinbase Full
quandl start_date/end_date dataset slice; the row parser generalizes to all rows Full
tsp the single-payload history endpoint sliced to the window Full
eastmoneyfund f10/lsjz NAV history with startDate/endDate (and the Referer header the API requires) Full

Design notes, applying the #1801/#1803 review lessons up front:

  • ECB cross-rates over a window are a per-date join of the two legs — the latest path's leg-date-mismatch bail has no historical counterpart, because unjoined days (a frozen HRK/RUB series) simply produce no point and the dispatch's on-or-before selection works with what joined.
  • Skip, never today-label: every parser skips observations with missing dates or unparsable values rather than falling back to a clock date — a today-fallback on a historical row would be discarded by the on-or-before selection and turn a served value into a spurious no-quote error.
  • Every parser is fixture-tested without HTTP (parse_series, parse_daily_series, parse_history, plus URL-form pins for all five) — the parse/fetch split from feat: window-primitive price source architecture (#1802) #1803 makes this nearly free.

How to test

cargo test -p rustledger price (626 tests, all hermetic). Live smoke: rledger price EUR -c USD -s ecb --date 2024-06-14, rledger price AAPL -s alphavantage --date 2024-06-14 (needs API key), rledger price 000001 -s eastmoneyfund --date 2024-06-14.

Part of #1802. Follow-ups still tracked there: typed SourceError, window write-through into the price cache, mock-HTTP fixture harness.

🤖 Generated with Claude Code

https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU

Ports the remaining #1802 table rows onto the window primitive:

- ecb: fetch_series over the SDMX data API with startPeriod/endPeriod
  (the full EU-reference series back to 1999-01-04, not just the
  90-day XML feed); cross-rates over a window are a PER-DATE join of
  the two legs, so the latest-path leg-mismatch bail has no historical
  counterpart - unjoined days (frozen HRK/RUB series) simply yield no
  point. parse_series is fixture-tested; observations with missing
  dates or null rates are skipped, never today-labeled.
- alphavantage: TIME_SERIES_DAILY for stock tickers (compact/full
  outputsize chosen by window age); forex and crypto ticker forms
  refuse hermetically before any network I/O with a pointer at
  ratesapi/coinbase. parse_daily_series is fixture-tested including
  the rate-limit Note shape.
- quandl: start_date/end_date dataset slice; fetch_rows generalizes
  the row parser to all rows (skip-not-fallback on malformed rows) and
  the latest path picks the greatest-dated row.
- tsp: the single-payload history endpoint is sliced to the window;
  per-fund missing days are skipped (funds launch at different times).
- eastmoneyfund: the f10/lsjz NAV-history endpoint with
  startDate/endDate and the required Referer header; parse_history is
  fixture-tested including empty-DWJZ days and the ErrCode bail.

Latest-only is now just coincap, coinmarketcap, and oanda (paid-tier
or product-gap questions per the issue). Capability wiring tests and
the docs --date row updated accordingly.
Copilot AI review requested due to automatic review settings July 18, 2026 12:44
@robcohen
robcohen requested a review from a team as a code owner July 18, 2026 12:44
@codecov

codecov Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 34.6ms ± 3.7ms 23.7 MB
beancount 896.9ms ± 7.6ms 50.6 MB
Comparison 25.9x faster 2.1x less

vs main branch (2026-07-18)

Metric main this PR Change
Time 35.6ms 34.6ms -2.8% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the remaining historical-capable price sources from issue #1802 onto the fetch_window primitive introduced in #1803, so rledger price --date ... can return correctly dated on-or-before quotes (rather than refusing or mislabeling latest quotes) for these providers.

Changes:

  • Implement historical coverage declarations and fetch_window for ecb, alphavantage, quandl, tsp, and eastmoneyfund.
  • Add hermetic (no-network) parser fixtures for ECB/AlphaVantage/EastMoneyFund (and URL-form tests for ECB/Quandl/EastMoneyFund).
  • Update docs and capability wiring tests to reflect the new historical-capable vs latest-only source set.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/commands/price.md Updates CLI docs to list which sources now support historical --date and which remain latest-only.
crates/rustledger/src/cmd/price/sources/mod.rs Updates capability wiring tests for latest-only vs historical-capable built-ins and asserts historical coverage declarations.
crates/rustledger/src/cmd/price/sources/ecb.rs Adds SDMX window fetching (startPeriod/endPeriod), series parsing, and per-date cross-rate joins for historical quotes.
crates/rustledger/src/cmd/price/sources/alphavantage.rs Adds TIME_SERIES_DAILY window fetching + parsing for stock tickers, with hermetic refusal for forex/crypto historical requests.
crates/rustledger/src/cmd/price/sources/quandl.rs Adds windowed dataset slicing via start_date/end_date and parses all returned rows into dated points.
crates/rustledger/src/cmd/price/sources/tsp.rs Refactors latest fetching via a shared history fetch and adds window slicing over the single-payload history endpoint.
crates/rustledger/src/cmd/price/sources/eastmoneyfund.rs Adds windowed NAV history fetch (lsjz) with required Referer header plus hermetic parsing of LSJZList rows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- dispatch: reject_url_metacharacters guards ticker and currency once
  before any routing - values flow into provider URLs unescaped in
  every source, and a crafted ticker like 000001^endDate=2019-01-01
  from shared-ledger metadata could rewrite the window parameters
- ecb: an SDMX 404 (empty selection) is the contract empty vec, not a
  transport error (a frozen HRK window read as a network failure);
  parse_series takes an undated-observation fallback so the LATEST
  path today-labels like main while historical rows still skip
- alphavantage: drop the still-open US/Eastern session bar from window
  results (a UTC+8 local-yesterday can be the live US session, whose
  partial bar must not become a settled close); dated forex refusal is
  pinned through the dispatch, not just fetch_window; canonical
  feed_date for the series keys
- quandl: fetch_rows takes the same latest-vs-historical date-fallback
  split; the latest empty message names the actual causes
- eastmoneyfund: DWJZ parses via the canonical price_decimal_from_json
  (string AND number shapes); ErrCode tolerates string typing; windows
  wider than one 49-entry page refuse explicitly instead of silently
  truncating
- tsp/quandl/eastmoneyfund/ecb: inline date slice-and-parse copies
  replaced by the canonical feed_date helper
@robcohen

Copy link
Copy Markdown
Member Author

Round-1 deep review (25 agents, adversarial verification): 10 findings (9 confirmed, 1 plausible hardened), all addressed in e82f9f7.

  1. ECB empty windows violated the fetch_window contract: the SDMX API answers an empty selection with HTTP 404, which surfaced as a raw transport error instead of the dispatch's clean no-quote message — a frozen HRK window read as a network outage. 404 now maps to the contract's empty vec.
  2. alphavantage could serve a live in-progress bar as a settled close: the dispatch's past-vs-today split uses the local calendar while TIME_SERIES_DAILY days are US/Eastern — a UTC+8 user's local "yesterday" can be the still-open US session. The window path now drops the Eastern-today bar (pure helper, unit-tested).
  3. URL-parameter injection closed at the dispatch: tickers/currencies flow into provider URLs unescaped in every source, and a crafted ticker (000001&endDate=2019-01-01 from shared-ledger price: metadata) could rewrite the window parameters. reject_url_metacharacters now guards both values once, canonically, before any routing — real ticker shapes (BRK.B, CRYPTO:BTC, WIKI/AAPL, EURUSD=X) pass, and the pre-existing latest-path exposure closes with it.
  4. Two latest-path regressions restored: the series refactors had dropped the LATEST-fetch today-fallback for undateable rows in ecb and quandl, turning rates main served into misleading hard errors. Both parsers now take an explicit undated-fallback (today on the latest path, skip on the historical path — the same split feed_date_or documents).
  5. eastmoneyfund hardening: DWJZ parses via the canonical price_decimal_from_json (string and number shapes, like every sibling parser); ErrCode tolerates string typing; and windows wider than one 49-entry page refuse explicitly instead of silently truncating (paging can come with a real consumer).
  6. The dispatch-level hermetic pin is restored: dated_forex_refuses_through_the_dispatch exercises alphavantage's forex refusal through fetch_price, not just a direct fetch_window call — a future dispatch reorder can't silently unhermeticize it.
  7. Canonical-function discipline: the three inline date slice-and-parse copies (quandl/tsp/eastmoneyfund) now call the new strict feed_date helper, which feed_date_or delegates to.

628 tests green, clippy/doc clean.

@robcohen
robcohen enabled auto-merge (squash) July 18, 2026 13:11
@robcohen
robcohen merged commit 8e30947 into main Jul 18, 2026
43 checks passed
@robcohen
robcohen deleted the feat/price-window-ports branch July 18, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants