Skip to content

feat(quote): symbol_to_counter_ids API with cached local-first resolution#538

Merged
huacnlee merged 2 commits into
mainfrom
symbol-to-counter-ids
Jun 4, 2026
Merged

feat(quote): symbol_to_counter_ids API with cached local-first resolution#538
huacnlee merged 2 commits into
mainfrom
symbol-to-counter-ids

Conversation

@huacnlee

@huacnlee huacnlee commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

  • QuoteContext::symbol_to_counter_ids(symbols) — batch symbol → counter_id conversion via the new POST /v1/quote/symbol-to-counter-ids endpoint (request {ticker_regions: [\"TSLA.US\", \"700.HK\"]}, response {list: {symbol: counter_id}}; unrecognized symbols are omitted)
  • QuoteContext::resolve_counter_ids(symbols) — local-first resolution: embedded ETF/IX/WT directory + resolved-cache hits are answered without network; remaining symbols are resolved in one batch remotely, persisted to ~/.longbridge/cache/counter-ids.csv (one counter_id per line, same format as the embedded directory files; directory overridable via LONGBRIDGE_CACHE_DIR), and answered from cache afterwards. Backend-unrecognized symbols fall back to the default ST/ conversion (and are not cached)
  • The cache is a counter_id set; lookups match ETF/IX/WT/ST prefix candidates against it — backend-confirmed ST/ entries are cached too, so repeat resolutions of plain stocks also skip the network
  • counter module gains lookup_counter_id / cache_counter_ids; symbol_to_counter_id now also consults the resolved cache — so newly listed instruments missing from the embedded directory (the DRAM.US class of problem) resolve correctly after the first remote query
  • Blocking wrappers on QuoteContextSync; Rust only for now (bindings to follow as needed)

Verification

  • cargo test -p longbridge --lib utils::counter: 24 passed (incl. CSV cache roundtrip + local lookup tests)
  • cargo clippy --all --all-features: clean
  • Live against staging: resolve_counter_ids([\"DRAM.US\", \"TSLA.US\", \"QQQ.US\", \"NEWFAKE.US\"]) → DRAM/QQQ resolved locally, TSLA resolved remotely and persisted to the cache file, NEWFAKE fell back to ST/US/NEWFAKE without being cached

🤖 Generated with Claude Code

huacnlee and others added 2 commits June 4, 2026 15:50
…solution

- QuoteContext::symbol_to_counter_ids(symbols): batch conversion via
  POST /v1/quote/symbol-to-counter-ids (unrecognized symbols omitted)
- QuoteContext::resolve_counter_ids(symbols): local-first (embedded
  ETF/IX/WT directory + cache), remote fallback for unknown symbols,
  results persisted to ~/.longbridge/cache/counter-ids.json
  (LONGBRIDGE_CACHE_DIR overridable)
- counter module gains lookup_counter_id / cache_counter_ids;
  symbol_to_counter_id now also consults the resolved cache, so newly
  listed instruments missing from the embedded directory resolve
  correctly after the first remote query
- blocking wrappers on QuoteContextSync

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
~/.longbridge/cache/counter-ids.json -> counter-ids.csv, same format as
the embedded directory files. The cache is now a counter_id set; symbol
lookup matches ETF/IX/WT/ST prefix candidates against it, so
backend-confirmed ST/ entries are also cached and answered locally.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@huacnlee huacnlee merged commit c30a1c4 into main Jun 4, 2026
56 checks passed
@huacnlee huacnlee deleted the symbol-to-counter-ids branch June 4, 2026 08:47
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