Repository navigation
feat(price): implement custom price sources with pluggable registry - #624
Merged
Merged
Conversation
Adds 11 native Rust price sources and external command support for fetching commodity prices. This replaces the previous Yahoo-only implementation with a flexible, configurable system. New price sources (no API key required): - yahoo: stocks, ETFs, crypto, forex - coinbase: cryptocurrency spot prices - coincap: cryptocurrency prices - ecb: European Central Bank exchange rates - ratesapi: currency exchange rates - tsp: Thrift Savings Plan fund prices - eastmoneyfund: Chinese mutual fund prices New price sources (API key required): - alphavantage: stocks, forex, crypto - oanda: forex rates - coinmarketcap: cryptocurrency prices - quandl: Nasdaq Data Link financial datasets Additional features: - External command source for custom price fetchers - Configurable commodity mappings with fallback chains - Source-specific ticker transformations - CLI options: --source, --source-cmd, --list-sources Closes #571 Co-Authored-By: Claude Opus 4.5 <[email protected]>
Security: - Add ticker validation to prevent command injection in external sources - Reject shell metacharacters, path separators, and flag-like tickers Improvements: - Register all API key sources unconditionally (clearer error on use) - Add UTF-8 safe string slicing in eastmoneyfund date parsing - Document timeout field limitations with ureq 3.x - Add TODO for unimplemented cache_ttl feature - Add tests for ticker validation Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-03-31)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Implements a new pluggable price-fetching system for rledger price, adding a configurable registry of built-in HTTP sources plus external command execution, and wiring the new price configuration through CLI/config loading.
Changes:
- Added
[price]configuration (default source, timeout, source definitions, commodity mappings) with merge/effective-default helpers. - Introduced
cmd::pricemodule withPriceSourceRegistry,PriceRequest/Response, built-in sources, and an external-command source. - Updated
priceCLI to support--source,--source-cmd, and--list-sources, and to use the registry/mappings.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger/src/config.rs | Adds PriceConfig + serde models for sources/mappings and merge logic. |
| crates/rustledger/src/cmd/price/mod.rs | New price module (registry, request/response, mapping resolution). |
| crates/rustledger/src/cmd/price/external.rs | External command-backed price source with output parsing and ticker validation. |
| crates/rustledger/src/cmd/price/sources/mod.rs | Defines PriceSource trait + exports built-in sources. |
| crates/rustledger/src/cmd/price/sources/yahoo.rs | Yahoo Finance implementation. |
| crates/rustledger/src/cmd/price/sources/coinbase.rs | Coinbase spot price implementation. |
| crates/rustledger/src/cmd/price/sources/coincap.rs | CoinCap implementation. |
| crates/rustledger/src/cmd/price/sources/ecb.rs | ECB exchange-rate implementation. |
| crates/rustledger/src/cmd/price/sources/ratesapi.rs | exchangerate.host-based FX implementation. |
| crates/rustledger/src/cmd/price/sources/tsp.rs | TSP fund price implementation. |
| crates/rustledger/src/cmd/price/sources/eastmoneyfund.rs | EastMoney fund NAV implementation. |
| crates/rustledger/src/cmd/price/sources/alphavantage.rs | AlphaVantage implementation (API key). |
| crates/rustledger/src/cmd/price/sources/oanda.rs | OANDA implementation (API key). |
| crates/rustledger/src/cmd/price/sources/coinmarketcap.rs | CoinMarketCap implementation (API key). |
| crates/rustledger/src/cmd/price/sources/quandl.rs | Nasdaq Data Link/Quandl implementation (API key). |
| crates/rustledger/src/cmd/price_cmd.rs | Reworks CLI command to use registry + new flags. |
| crates/rustledger/src/cmd/mod.rs | Registers cmd::price module. |
| crates/rustledger/src/bin/rledger.rs | Wires config.price into price_cmd::run. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Fixes several issues identified in PR #624 review: 1. Yahoo f64 precision (issue #3): Use pattern matching with serde_json::Value::Number to preserve decimal precision instead of converting through f64. 2. ECB cross-rate handling (issue #2): Rewrite fetch_price to correctly handle EUR→X, X→EUR, and X→Y cross-rate conversions. 3. --source-cmd early return (issue #4): Move external command handling after symbol discovery so -f flag works with --source-cmd. 4. Hardcoded timeout (issue #7): Use config timeout for --source-cmd instead of hardcoded 30 seconds. 5. External source naming (issue #8): Derive source name from command binary name instead of always returning "external". Add with_name() constructor for configured sources. 6. Unknown sources warning (issue #5): Track and report unknown sources in fallback chains when price fetching fails. 7. Timeout limitation (issue #6): Document that timeout is stored but not enforced due to std::process::Command limitations. Co-Authored-By: Claude Opus 4.5 <[email protected]>
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
Implements #571 - a pluggable price source system with 11 native Rust sources and external command support.
New price sources (no API key required):
yahoo- stocks, ETFs, crypto, forexcoinbase- cryptocurrency spot pricescoincap- cryptocurrency pricesecb- European Central Bank exchange ratesratesapi- currency exchange ratestsp- Thrift Savings Plan fund priceseastmoneyfund- Chinese mutual fund pricesNew price sources (API key required):
alphavantage- stocks, forex, cryptooanda- forex ratescoinmarketcap- cryptocurrency pricesquandl- Nasdaq Data Link financial datasetsAdditional features:
--source,--source-cmd,--list-sourcesTest plan
rledger price AAPL --source yahoorledger price BTC --source coinbaserledger price --list-sourcesrledger price AAPL --source-cmd "echo 150.00 USD"Closes #571
🤖 Generated with Claude Code