Bourse.WS.Adapter (bourse v0.1.0)

Copy Markdown View Source

Layer-3 WebSocket adapter GenServer.

Manages connection lifecycle, auth state machine, subscription restoration, spec-driven message routing, semantics state, and Registry broadcast.

Summary

Functions

Returns current auth state.

Runs the auth state machine when credentials are configured.

Returns a specification to start this module under a supervisor.

Returns connection state from the underlying WS client.

Starts a managed WS adapter for the given exchange section.

Subscribes to channels and tracks them for restoration.

Types

auth_state()

@type auth_state() :: :unauthenticated | :authenticating | :authenticated | :expired

section()

@type section() :: Bourse.WS.section()

t()

@type t() :: %Bourse.WS.Adapter{
  auth_context: map() | nil,
  auth_state: auth_state(),
  auth_timer_ref: reference() | nil,
  connect_fun: (Bourse.Exchange.t(), section(), keyword() ->
                  {:ok, Bourse.WS.t()} | {:error, term()}),
  exchange: Bourse.Exchange.t(),
  ohlcv: Bourse.WS.Semantics.Ohlcv.t(),
  orderbook: Bourse.WS.Semantics.Orderbook.t(),
  section: section(),
  subscriptions: [String.t() | map()],
  trades: Bourse.WS.Semantics.Trades.t(),
  ws: Bourse.WS.t() | nil
}

Functions

auth_state(server)

@spec auth_state(GenServer.server()) :: auth_state()

Returns current auth state.

authenticate(server)

@spec authenticate(GenServer.server()) :: :ok | {:error, term()}

Runs the auth state machine when credentials are configured.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

connection_state(server)

@spec connection_state(GenServer.server()) :: :connecting | :connected | :disconnected

Returns connection state from the underlying WS client.

start_link(exchange, section, opts \\ [])

@spec start_link(Bourse.Exchange.t(), section(), keyword()) :: GenServer.on_start()

Starts a managed WS adapter for the given exchange section.

subscribe(server, channels, opts \\ [])

@spec subscribe(GenServer.server(), [String.t() | map()], keyword() | map()) ::
  :ok | {:ok, map()} | {:error, term()}

Subscribes to channels and tracks them for restoration.