Expand description
Symbol โ counter_id conversion utilities.
A counter_id is the internal instrument identifier used by the
Longbridge backend, e.g. ST/US/TSLA, ETF/US/SPY, IX/HK/HSI,
WT/HK/10005. These helpers convert between user-facing symbols
(e.g. TSLA.US, 700.HK, .DJI.US) and counter IDs, using an
embedded ETF + index + warrant directory to pick the right prefix.
The embedded directory may lag behind newly listed instruments. Entries
resolved remotely (see QuoteContext::resolve_counter_ids) are persisted
to a local cache file and consulted on subsequent lookups.
Functionsยง
- cache_
counter_ ids - Merge remotely resolved counter IDs into the local cache (in memory and
on disk), so subsequent
symbol_to_counter_id/lookup_counter_idcalls resolve them without another network round trip. - counter_
id_ to_ symbol - Convert a counter_id (e.g.
ST/US/TSLA,ETF/US/SPY,IX/US/.DJI,ST/HK/700) back to a display symbol (e.g.TSLA.US,SPY.US,.DJI.US,700.HK). - index_
symbol_ to_ counter_ id - Convert an index symbol (e.g.
HSI.HK) to counter_id (e.g.IX/HK/HSI), always using theIX/prefix. - is_etf
- Whether a user-supplied symbol resolves to an ETF (e.g.
QQQ.US,SPY.US). - lookup_
counter_ id - Look up a symbol in the local directory only (embedded special set, the
remote-resolved cache, and leading-dot index notation). Returns
Nonewhen the symbol is unknown locally โ i.e.symbol_to_counter_idwould fall back to the defaultST/prefix, which may be wrong for newly listed ETFs / indexes / warrants. - symbol_
to_ counter_ id - Convert a user-supplied symbol (e.g.
TSLA.US,700.HK,.DJI.US,HSI.HK) to a counter_id (e.g.ST/US/TSLA,ST/HK/700,IX/US/.DJI,IX/HK/HSI).