REST Token auth pattern — kraken.
Similar to ListenKey in that the real work happens over REST — the
adapter calls privatePostGetWebSocketsToken, extracts the token from
the response, and passes it back through config[:token] (or an opts
map; see CCXT.WS.Auth.build_subscribe_auth/5) so subscribe frames can
include %{"token" => token}.
Flow
- Call REST endpoint from
config[:pre_auth][:endpoint]→ returns%{"result" => %{"token" => "...", "expires" => 900}} - Connect to WS (no auth frame)
- Inject
%{"token" => token}into each private subscribe frame viaCCXT.WS.Auth.build_subscribe_auth(:rest_token, creds, config_with_token, …) - Token expires (~15 min); adapter refreshes via another REST call
Config
config = %{
pre_auth: %{endpoint: "privatePostGetWebSocketsToken"},
token: "xeAQ/…" # set by caller after REST round-trip, used for subscribe injection
}Returns from pre_auth/3
{:ok, %{endpoint:, credentials:}}
| {:error, :no_token_endpoint}