Skip to main content

Module counter

Module counter 

Source
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_id calls 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 the IX/ 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 None when the symbol is unknown locally โ€” i.e. symbol_to_counter_id would fall back to the default ST/ 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).