feat(fundamental): add etf_asset_allocation API#535
Merged
Conversation
Add `etf_asset_allocation(symbol)` to QuoteContext across all SDKs (Rust, Python, Node.js, C, C++), querying `GET /v1/quote/etf-asset-allocation` for ETF asset allocation grouped by element type (Holdings / Regional / AssetClass / Industry). - New types: AssetAllocationResponse / AssetAllocationGroup / AssetAllocationItem / HoldingDetail and ElementType enum - Public param is `symbol`, converted internally via symbol_to_counter_id; counter_id in responses converted back to symbol - name_locales_map exposed as locale → name map (C uses lb_locale_name_t pair array, sorted by locale) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 4, 2026
huacnlee
added a commit
that referenced
this pull request
Jun 4, 2026
… FundamentalContext (#536) ## Summary Follow-up to #535 (merged with the API on `QuoteContext`): relocate `etf_asset_allocation` and its types (`AssetAllocationResponse` / `AssetAllocationGroup` / `AssetAllocationItem`, `HoldingDetail`, `ElementType`) to the fundamental module across all languages. - **Rust:** types/method moved to `fundamental`; blocking wrapper moved to `FundamentalContextSync` - **Python:** classes registered under fundamental module; method on `FundamentalContext` / `AsyncFundamentalContext`; `openapi.pyi` updated - **Node.js:** `etfAssetAllocation` now on `FundamentalContext`; `index.d.ts`/`index.js` regenerated - **C:** `lb_quote_context_etf_asset_allocation` → `lb_fundamental_context_etf_asset_allocation`; FFI types moved to `fundamental_context`; `longbridge.h` regenerated - **C++:** method moved to `fundamental::FundamentalContext`; types moved to `namespace fundamental` - CHANGELOG `[Unreleased]` entry updated accordingly ## Breaking change note `QuoteContext::etf_asset_allocation` was only on main briefly (unreleased), so moving it pre-release avoids shipping it in the wrong context. ## Verification - `cargo clippy --all --all-features`: clean - `cargo +nightly fmt --all`: applied - All crates compile; C++ checked with `-fsyntax-only` - Verified end-to-end against staging via the CLI integration (`QQQ.US` returns all four allocation groups) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
huacnlee
added a commit
to longbridge/longbridge-terminal
that referenced
this pull request
Jun 4, 2026
## Summary - `constituent` now detects ETF symbols (via `is_etf()` — embedded special counter_id set) and switches to the new SDK API `FundamentalContext::etf_asset_allocation` (openapi PR [longbridge/openapi#535](longbridge/openapi#535)) - ETF output: four grouped tables (Holdings / Regional / Asset Class / Industry) with `report_date`, percentage-formatted weights, locale-aware names; `--format json` serializes the full `AssetAllocationResponse` - `--limit` caps Holdings rows; `--sort`/`--order` are ignored for the pre-ranked allocation data - Fallback: if an ETF returns empty allocation `info`, falls through to the original `/v1/quote/index-constituents` source; index symbols are completely unchanged - No standalone `etf-asset-allocation` command — folded into `constituent` per review feedback ## Usage ``` longbridge constituent QQQ.US # ETF → asset allocation groups longbridge constituent QQQ.US --format json longbridge constituent HSI.HK # index → constituents (unchanged) ``` ## Dependency note `Cargo.toml` temporarily points `longbridge` at the openapi `etf-allocation` branch (rev `f449901`, FundamentalContext API) — **revert to `main` after longbridge/openapi#535 merges** (TODO comment in place). ## Verification (staging) - `constituent QQQ.US`: four grouped tables rendered correctly - `constituent QQQ.US --format json`: valid `AssetAllocationResponse` JSON (4 groups, 10 holdings) - `constituent HSI.HK --limit 5`: original index-constituents table unchanged - `constituent 2800.HK`: takes original path, no error - `cargo build` / clippy clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
huacnlee
added a commit
to longbridge/longbridge-mcp
that referenced
this pull request
Jun 4, 2026
## Summary - `constituent` tool now detects ETF symbols (`symbol_to_counter_id` → `ETF/` prefix) and switches to the new SDK API `FundamentalContext::etf_asset_allocation` (openapi PR [longbridge/openapi#535](longbridge/openapi#535)) - ETF response: `AssetAllocationResponse` JSON — `info[]` grouped by element type (1=Holdings, 2=Regional, 3=AssetClass, 4=Industry), each group carrying `report_date` and `lists[]` (name, position_ratio, name_locales; Holdings additionally code / symbol / holding_detail) - Fallback: ETF with empty allocation `info` falls through to the original index-constituents source; index symbols unchanged - No standalone `etf_asset_allocation` tool — folded into `constituent` per review feedback (tool count stays 145) - `constituent` description (EN + zh-CN + zh-HK) documents both response shapes ## Dependency note `Cargo.toml` temporarily points `longbridge` at the openapi `etf-allocation` git branch (rev `f449901`) — **switch back to crates.io after longbridge/openapi#535 merges and releases** (TODO comment in place). ## Verification - `cargo build`: success - `cargo clippy --all-features --all-targets`: no issues - `cargo +nightly fmt`: no changes; locale JSON validated 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
etf_asset_allocation(symbol)toFundamentalContextin all SDKs (Rust, Python, Node.js, C, C++), queryingGET /v1/quote/etf-asset-allocationfor ETF asset allocation grouped by element type (Holdings/Regional/AssetClass/Industry)AssetAllocationResponse→AssetAllocationGroup→AssetAllocationItem→HoldingDetail, plusElementTypeenum (Unknown=0/Holdings=1/Regional=2/AssetClass=3/Industry=4)symbol(e.g.QQQ.US), converted internally viasymbol_to_counter_id(with US ETF detection);counter_idin responses is converted back to standard symbol formatname_locales_mapexposed as locale → name map (HashMapin Rust,dictin Python, object in Node.js,std::mapin C++; C uses alb_locale_name_tpair array sorted by locale)Per-SDK changes
fundamental/types.rs,fundamental/context.rs,blocking/fundamental.rsopenapi.pyistubsFundamentalContext.etfAssetAllocation;index.d.ts/index.jsregenerated vianpm run build:debugCElementTypeenum, FFI types infundamental_context,lb_fundamental_context_etf_asset_allocation,cbindgen.tomlexports;longbridge.hregeneratednamespace fundamental,convert.hpp,fundamental_context.hpp/.cppVerification
cargo clippy --all --all-features: cleancargo +nightly fmt --all: applied-fsyntax-onlyopenapi.longbridge.xyz) — all four allocation groups returned correctly forQQQ.US🤖 Generated with Claude Code