# `Bourse.WS.Adapter`
[🔗](https://github.com/ZenHive/bourse/blob/main/lib/bourse/ws/adapter.ex#L1)

Layer-3 WebSocket adapter GenServer.

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

# `auth_state`

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

# `section`

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

# `t`

```elixir
@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() -&gt;
                  {: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
}
```

# `auth_state`

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

Returns current auth state.

# `authenticate`

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

Runs the auth state machine when credentials are configured.

The call window is longer than the GenServer default because the handshake
waits on the venue: `Bourse.WS.authenticate/2` allows 10s for a verdict, and a
5s call timeout would abandon a handshake that is still legitimately in
flight.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `connection_state`

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

Returns connection state from the underlying WS client.

# `start_link`

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

Starts a managed WS adapter for the given exchange section.

# `subscribe`

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

Subscribes to channels and tracks them for restoration.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
