Documentation
¶
Overview ¶
Package counter provides 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 quote.QuoteContext.ResolveCounterIds) are persisted to a local cache file and consulted on subsequent lookups.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheCounterIDs ¶
func CacheCounterIDs(counterIDs []string)
CacheCounterIDs merges remotely resolved counter IDs into the local cache (in memory and on disk), so subsequent SymbolToCounterID / LookupCounterID calls resolve them without another network round trip. The cache file is rewritten with one counter_id per line in lexicographic order. Writing is skipped when no new entry is added.
func CounterIDToSymbol ¶
CounterIDToSymbol converts 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").
US index counter IDs ("IX/US/...") preserve the leading dot in the code part (e.g. "IX/US/.DJI" → ".DJI.US"). An input that is not in the three-segment counter_id format is returned unchanged.
func IndexSymbolToCounterID ¶
IndexSymbolToCounterID converts an index symbol (e.g. "HSI.HK") to a counter_id (e.g. "IX/HK/HSI"), always using the "IX/" prefix. An input without a "." is returned unchanged.
func IsETF ¶
IsETF reports whether a user-supplied symbol resolves to an ETF (e.g. "QQQ.US", "SPY.US").
Determined by checking the embedded special counter_id set: a symbol is an ETF when SymbolToCounterID maps it to an "ETF/..." counter_id.
func LookupCounterID ¶
LookupCounterID looks up a symbol in the local directory only (embedded special set, the remote-resolved cache, and leading-dot index notation). It returns (counterID, true) on a match, or ("", false) when the symbol is unknown locally — i.e. SymbolToCounterID would fall back to the default "ST/" prefix, which may be wrong for newly listed ETFs / indexes / warrants.
func SymbolToCounterID ¶
SymbolToCounterID converts 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").
Leading-dot symbols (e.g. ".DJI.US") are US market indexes and always map to "IX/". All other symbols are checked against the embedded ETF + index + warrant set and the remote-resolved cache; a matching entry is returned as-is. Unmatched symbols default to "ST/". An input without a "." is returned unchanged.
Types ¶
This section is empty.