Skip to content

feat: add shareholders, screener, short-trades, rank, top-movers, valuation-comparison APIs#527

Open
hogan-yuan wants to merge 12 commits into
mainfrom
feat/shareholders-screener-short-trades-rank
Open

feat: add shareholders, screener, short-trades, rank, top-movers, valuation-comparison APIs#527
hogan-yuan wants to merge 12 commits into
mainfrom
feat/shareholders-screener-short-trades-rank

Conversation

@hogan-yuan
Copy link
Copy Markdown
Member

@hogan-yuan hogan-yuan commented May 20, 2026

Summary

Adds 13 new APIs across 4 contexts, ported from longbridge-mcp PR #49 and longbridge-terminal PR #209.

All responses use typed structs — not raw JSON:

  • counter_id fields are converted to symbol format (e.g. ST/US/TSLATSLA.US)
  • timestamp fields are converted to RFC 3339 (e.g. "1779202097""2026-05-19T14:48:17Z")
  • short_positions and short_trades use unified US+HK structs with market-specific optional fields

FundamentalContext (3 new methods)

Method Endpoint
shareholder_top(symbol) GET /v1/quote/shareholders/top
shareholder_detail(symbol, object_id) GET /v1/quote/shareholders/holding
valuation_comparison(symbol, currency, comparison_symbols?) GET /v1/quote/compare/valuation

QuoteContext (1 extended + 1 new)

Method Endpoint Notes
short_positions(symbol, count) GET /v1/quote/short-positions/hk or /us Extended: now supports HK+US unified
short_trades(symbol, count) GET /v1/quote/short-trades/hk or /us New; auto-detects market from suffix

MarketContext (3 new methods)

Method Endpoint Notes
top_movers(markets, sort, date, limit) POST /v1/quote/market/stock-events Renamed from stock_events
rank_categories() GET /v1/quote/market/rank/categories New
rank_list(key, need_article) GET /v1/quote/market/rank/list New

ScreenerContext (new context, 5 methods)

Method Endpoint
screener_recommend_strategies() GET /v1/quote/screener/strategies/recommend
screener_user_strategies() GET /v1/quote/screener/strategies/mine
screener_strategy(id) GET /v1/quote/screener/strategy
screener_search(market, strategy_id?, page, size) POST /v1/quote/screener/search
screener_indicators() GET /v1/quote/screener/indicators

Breaking changes

  • MarketContext::stock_events renamed to top_movers; StockEventsResponseTopMoversResponse
  • QuoteContext::hk_short_positions removed; use short_positions(symbol, count) which auto-detects market
  • ShortPositionsResponse is now typed (data: Vec<ShortPositionsItem>) instead of raw JSON

Languages

All 13 APIs implemented across Rust / Python / Node.js / Java / C / C++ with:

  • Full typed response structs in each language
  • Proper counter_id → symbol conversion
  • RFC 3339 timestamp formatting
  • Unified US+HK short-position/trade structs

Test plan

  • cargo clippy --all --all-features
  • cargo +nightly fmt --all
  • npm run build:debug
  • cargo build -p longbridge-c
  • Python 13/13 live API tests pass ✅
  • Go 7/7 typed struct tests pass ✅

🤖 Generated with Claude Code

hogan-yuan and others added 6 commits May 21, 2026 13:53
- FundamentalContext: shareholder_top, shareholder_detail, valuation_comparison
- QuoteContext: hk_short_positions, short_trades (auto-detects HK vs US endpoint)
- MarketContext: stock_events (POST), rank_categories, rank_list
- New ScreenerContext: screener_recommend_strategies, screener_user_strategies,
  screener_strategy, screener_search (POST), screener_indicators
- All methods have matching blocking (sync) wrappers
- All new response types use serde_json::Value for flexible raw-JSON payloads

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
… APIs to all language SDKs

Rust SDK:
- `short_positions(symbol, count)` now auto-detects market from symbol suffix
  (.HK → GET /v1/quote/short-positions/hk, else → /v1/quote/short-positions/us).
  `ShortPositionsResponse` is now a raw JSON wrapper (`data: serde_json::Value`).
  `hk_short_positions` and `ShortPosition` struct are removed.

Python / Node.js / Java / C / C++ SDKs:
- Port all 13 new Rust APIs added in the previous commit:
  - FundamentalContext: shareholder_top, shareholder_detail, valuation_comparison
  - QuoteContext: updated short_positions (HK+US, count param), short_trades
  - MarketContext: stock_events, rank_categories, rank_list
  - ScreenerContext (new): screener_recommend_strategies, screener_user_strategies,
    screener_strategy, screener_search, screener_indicators
- All new "raw JSON" responses expose data as a string (Java/C/C++/Node.js)
  or a Python object (Python, via pythonize).
- Updated openapi.pyi type stubs for all new types and methods.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ank_categories/rank_list

These were already declared in longbridge.h (via cbindgen); the manual
forward declarations in market_context.cpp had mismatched types
(const char** vs const char* const*, size_t vs uintptr_t).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…lization

The HTTP client extracts the `data` field from the API envelope before
deserializing into the target struct. Response structs with `data:
serde_json::Value` caused a double-unwrap — the inner JSON has no `data`
key, so deserialization failed with "missing field `data`".

Fix: deserialize to `serde_json::Value` first, then construct the response
struct explicitly. Affects 13 new methods across FundamentalContext,
QuoteContext, MarketContext, and ScreenerContext.

Verified against production API: Python SDK 17/17 pass.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Renames method, response type, C function, and C type across Rust,
Python, Node.js, Java, C, and C++ SDKs:
- `stock_events` → `top_movers` (Rust/Python/Node.js/Java/C/C++ method)
- `StockEventsResponse` → `TopMoversResponse` (Rust/Python/Node.js type)
- `CStockEventsResponse` → `CTopMoversResponse` (C Rust type)
- `lb_market_context_stock_events` → `lb_market_context_top_movers` (C extern fn)
- `lb_stock_events_response_t` → `lb_top_movers_response_t` (C header type)

C header (`longbridge.h`) regenerated via `cargo build -p longbridge-c`.
Node.js type definitions regenerated via `npm run build:debug`.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Previously only TopMovers was wired up. Now all missing pieces are in place:

SdkNative.java:
- Added native declarations for: marketContextRankCategories,
  marketContextRankList, newScreenerContext, freeScreenerContext,
  screenerContextRecommendStrategies/UserStrategies/Strategy/Search/Indicators,
  fundamentalContextShareholderTop/Detail/ValuationComparison,
  quoteContextShortTrades

New Java source files:
- fundamental/: ShareholderTopResponse, ShareholderDetailResponse,
  ValuationComparisonResponse, ShareholderDetailOptions, ValuationComparisonOptions
- market/: RankCategoriesResponse, RankListResponse, RankListOptions
- quote/: ShortTradesResponse, ShortTradesOptions
- screener/: ScreenerContext (new package), ScreenerRecommendStrategiesResponse,
  ScreenerUserStrategiesResponse, ScreenerStrategyResponse, ScreenerStrategyOptions,
  ScreenerSearchResponse, ScreenerSearchOptions, ScreenerIndicatorsResponse

Updated Java context classes:
- FundamentalContext.java: getShareholderTop, getShareholderDetail, getValuationComparison
- MarketContext.java: getRankCategories, getRankList
- QuoteContext.java: getShortTrades

Rust side (java/src/):
- types/classes.rs: impl_java_class! entries for all new response types
- init.rs: registered all new Rust types

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@hogan-yuan hogan-yuan force-pushed the feat/shareholders-screener-short-trades-rank branch from 5cdec48 to f18a5ae Compare May 21, 2026 05:56
hogan-yuan and others added 6 commits May 21, 2026 15:32
Replace serde_json::Value payloads in short_positions, short_trades,
rank_list, top_movers, and valuation_comparison with typed structs.
Unix-second timestamps are converted to RFC 3339 strings; counter_id
values are converted to dotted symbol notation (e.g. TSLA.US).
Python, Node.js, Java, and C bindings updated accordingly.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
API wraps the array in {"counter_id":"...","data":[...]} object.
Changed both methods to deserialize the outer object first, then
extract the inner data array.

Verified: Go 7/7 tests pass, Python short_positions/trades all RFC3339.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Replace raw-JSON stub structs with fully typed structs in Java, C, and C++
SDKs for five APIs: short_positions, short_trades (QuoteContext);
top_movers, rank_list (MarketContext); valuation_comparison
(FundamentalContext).

Java: add ShortPositionsItem, ShortTradesItem, TopMoversStock,
TopMoversEvent, TopMoversResponse, RankListItem, RankListResponse,
ValuationComparisonItem, ValuationHistoryPoint, ValuationComparisonResponse.

C: add CShortPositionsItem, CShortTradesItem, CTopMoversStock,
CTopMoversEvent, CTopMoversResponse, CRankListItem, CRankListResponse,
CValuationHistoryPoint, CValuationComparisonItem, CValuationComparisonResponse;
rebuild longbridge.h.

C++: add matching structs to types.hpp and convert functions to convert.hpp;
update market_context and fundamental_context to return typed responses.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
… institution_rating_views, industry_rank, industry_peers, financial_report_snapshot)

Implements the 6 missing C extern functions and corresponding C FFI types that
were preventing the C++ SDK from building. The `longbridge.h` header is
regenerated with all new `lb_*` type definitions and function declarations.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…xt.hpp

Methods business_segments, business_segments_history, institution_rating_views,
industry_rank, industry_peers, financial_report_snapshot were implemented in
fundamental_context.cpp but missing from the header, causing C++ CI failures.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…l_report_snapshot

The C function takes fiscal_year as const char*, not int32_t.
Convert to string before passing; treat 0 as nullptr (omitted).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@hogan-yuan hogan-yuan changed the title feat: add shareholders, screener, short-trades, rank, stock-events, valuation-comparison APIs feat: add shareholders, screener, short-trades, rank, top-movers, valuation-comparison APIs May 21, 2026
@hogan-yuan hogan-yuan marked this pull request as ready for review May 21, 2026 12:05
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