Skip to content

feat(fundamental): add etf_asset_allocation API#535

Merged
huacnlee merged 1 commit into
mainfrom
etf-allocation
Jun 4, 2026
Merged

feat(fundamental): add etf_asset_allocation API#535
huacnlee merged 1 commit into
mainfrom
etf-allocation

Conversation

@huacnlee
Copy link
Copy Markdown
Member

@huacnlee huacnlee commented Jun 4, 2026

Summary

  • Add etf_asset_allocation(symbol) to FundamentalContext in 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 (in the fundamental module): AssetAllocationResponseAssetAllocationGroupAssetAllocationItemHoldingDetail, plus ElementType enum (Unknown=0 / Holdings=1 / Regional=2 / AssetClass=3 / Industry=4)
  • Public parameter is symbol (e.g. QQQ.US), converted internally via symbol_to_counter_id (with US ETF detection); counter_id in responses is converted back to standard symbol format
  • name_locales_map exposed as locale → name map (HashMap in Rust, dict in Python, object in Node.js, std::map in C++; C uses a lb_locale_name_t pair array sorted by locale)

Per-SDK changes

SDK Changes
Rust fundamental/types.rs, fundamental/context.rs, blocking/fundamental.rs
Python types + sync/async FundamentalContext + module registration + openapi.pyi stubs
Node.js FundamentalContext.etfAssetAllocation; index.d.ts/index.js regenerated via npm run build:debug
C CElementType enum, FFI types in fundamental_context, lb_fundamental_context_etf_asset_allocation, cbindgen.toml exports; longbridge.h regenerated
C++ types in namespace fundamental, convert.hpp, fundamental_context.hpp/.cpp

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 (openapi.longbridge.xyz) — all four allocation groups returned correctly for QQQ.US

🤖 Generated with Claude Code

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>
@huacnlee huacnlee merged commit 48a70aa into main Jun 4, 2026
56 checks passed
@huacnlee huacnlee deleted the etf-allocation branch June 4, 2026 03:11
@huacnlee huacnlee changed the title feat(quote): add etf_asset_allocation API feat(fundamental): add etf_asset_allocation API 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>
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.

1 participant