Market context.
Provides market-level data: trading status, broker holdings, A/H share premiums, trade statistics, index constituents, and anomaly alerts.
All functions accept a Longbridge.Config struct and return
{:ok, data} | {:error, reason} tuples.
Usage
config = Longbridge.Config.new(...)
{:ok, status} = Longbridge.MarketContext.market_session(config, "US")
{:ok, constituents} = Longbridge.MarketContext.index_constituents(config, "HSI.HK")
Summary
Functions
Returns A/H share premium K-line data for a dual-listed security.
Lists market anomaly alerts (trading halts, suspensions, etc.).
Returns top broker holdings (buy/sell leaders) for a symbol.
Returns the constituents of a market index.
Returns the current trading session for all markets.
Lists rank categories for rank_list/2.
Returns the ranked security list for a rank category.
Returns top market movers — stocks whose price movement exceeds their 20-day standard deviation, with linked news context.
Returns buy/sell/neutral trade statistics for a symbol.
Functions
@spec anomaly_alerts(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}
Lists market anomaly alerts (trading halts, suspensions, etc.).
market is a region code: "US", "HK", "CN", "SG". Defaults
to "US".
Endpoint: GET /v1/quote/changes?market=<m>&category=0. The
response has "all_off" (true if no active alerts) and "changes"
(list of %{"symbol", "type", "title_cn" | "title_en", "update_at"}
entries).
@spec broker_holdings(Longbridge.Config.t(), String.t(), keyword(), keyword()) :: {:ok, map()} | {:error, term()}
Returns top broker holdings (buy/sell leaders) for a symbol.
Options
:period—:rct_1(1d, default),:rct_5,:rct_20,:rct_60
@spec index_constituents(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}
Returns the constituents of a market index.
index_symbol examples: "HSI.HK", "HSCEI.HK", "HSTECH.HK".
@spec market_session( Longbridge.Config.t(), keyword() ) :: {:ok, map()} | {:error, term()}
Returns the current trading session for all markets.
The upstream /v1/quote/market-status endpoint does not accept a
market filter; the response includes US/HK/CN/SG entries that callers
filter client-side.
@spec rank_categories( Longbridge.Config.t(), keyword() ) :: {:ok, list()} | {:error, term()}
Lists rank categories for rank_list/2.
Endpoint: GET /v1/quote/market/rank/categories
Returns a list of categories keyed by their ib_<key> IDs.
Pass the value of a category entry's key field to rank_list/2.
@spec rank_list(Longbridge.Config.t(), String.t(), keyword(), keyword()) :: {:ok, map()} | {:error, term()}
Returns the ranked security list for a rank category.
Endpoint: GET /v1/quote/market/rank/list?key=ib_<key>
Pass the key value from one of the entries returned by
rank_categories/1. The ib_ prefix is added automatically if
missing.
Options
:need_article— boolean (defaultfalse). Whentrue, the response includes article content.
@spec top_movers(Longbridge.Config.t(), keyword(), keyword()) :: {:ok, map()} | {:error, term()}
Returns top market movers — stocks whose price movement exceeds their 20-day standard deviation, with linked news context.
Endpoint: POST /v1/quote/market/stock-events
Options
:markets— list of"HK" | "US" | "CN" | "SG". Omit (or pass[]) for all markets.:sort—:hot(default),:time, or:change.:date—"YYYY-MM-DD"filter. Optional.:limit— integer 1-100, default 20.
Renamed from stock_events in longbridge/openapi 4.2.0.
@spec trade_status(Longbridge.Config.t(), String.t(), keyword()) :: {:ok, map()} | {:error, term()}
Returns buy/sell/neutral trade statistics for a symbol.
Endpoint: GET /v1/quote/trades-statistics?counter_id=.... The
response is shaped as
%{"statistics" => %{"buy_ratio" => ..., "sell_ratio" => ..., ...}, "trades" => [%{"price", "volume", "direction", "ts"}, ...]}
— a windowed summary plus the recent trade tape used to derive it.
@spec trading_days(Longbridge.Config.t(), String.t(), String.t(), String.t()) :: {:error, :removed_upstream}