feat(quote): symbol_to_counter_ids API with cached local-first resolution#538
Merged
Conversation
…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>
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
QuoteContext::symbol_to_counter_ids(symbols)— batch symbol → counter_id conversion via the newPOST /v1/quote/symbol-to-counter-idsendpoint (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 viaLONGBRIDGE_CACHE_DIR), and answered from cache afterwards. Backend-unrecognized symbols fall back to the defaultST/conversion (and are not cached)ETF/IX/WT/STprefix candidates against it — backend-confirmedST/entries are cached too, so repeat resolutions of plain stocks also skip the networkcountermodule gainslookup_counter_id/cache_counter_ids;symbol_to_counter_idnow 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 queryQuoteContextSync; 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: cleanresolve_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 toST/US/NEWFAKEwithout being cached🤖 Generated with Claude Code