CCXT.WS.Auth.ListenKey (ccxt_client v0.6.1)

Copy Markdown View Source

Listen Key auth pattern — binance family, aster.

pre_auth/3 resolves the correct REST endpoint for the current market type from config[:pre_auth][:endpoints]. The actual REST call, listen key extraction, WS URL embedding, and periodic refresh all happen in the adapter layer (T94/T95) — this module is pure endpoint resolution so it stays network-free and unit-testable.

Pre-auth Endpoints by Market Type

MarketEndpoint
Linear (USD-M)fapiPrivatePostListenKey
Inverse (COIN-M)dapiPrivatePostListenKey
SpotpublicPostUserDataStream
MarginsapiPostUserDataStream
Isolated marginsapiPostUserDataStreamIsolated
Portfolio marginpapiPostListenKey

Config / opts

config = %{
  pre_auth: %{
    endpoints: [
      %{type: :spot, endpoint: "publicPostUserDataStream", ...},
      %{type: :linear, endpoint: "fapiPrivatePostListenKey", ...}
    ]
  }
}

opts[:market_type]  # :spot | :linear | :inverse | :margin | ...
                    # :future and :delivery are normalized to :linear/:inverse

Returns from pre_auth/3

{:ok, %{endpoint:, market_type:, api_section:, method:, path:, credentials:}}
| {:error, {:no_endpoint_for_market_type, %{requested:, normalized:, available:}}}