View Source Hyperliquid.WebSocket.Connection (hyperliquid v0.2.2)

WebSocket connection handler with automatic reconnection.

Manages a single WebSocket connection to Hyperliquid, handling:

  • Connection establishment and authentication
  • Subscription management
  • Message routing
  • Automatic reconnection with exponential backoff

Usage

Typically managed by Hyperliquid.WebSocket.Manager, but can be used directly:

{:ok, pid} = Connection.start_link(
  key: "l2Book:BTC:5",
  manager: manager_pid,
  url: "wss://api.hyperliquid.xyz/ws"
)

# Subscribe
Connection.subscribe(pid, %{type: "l2Book", coin: "BTC", nSigFigs: 5}, "sub_123")

# Unsubscribe
Connection.unsubscribe(pid, "sub_123")

Summary

Functions

Returns a specification to start this module under a supervisor.

Lookup connection by key.

Start a WebSocket connection.

Get connection status.

Subscribe to a channel on this connection.

Unsubscribe from a channel.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec lookup(String.t()) :: {:ok, pid()} | {:error, :not_found}

Lookup connection by key.

Start a WebSocket connection.

Options

  • :key - Required. Connection identifier
  • :manager - Required. Manager PID for message routing
  • :url - WebSocket URL (default: wss://api.hyperliquid.xyz/ws)
@spec status(pid() | String.t()) :: map()

Get connection status.

Link to this function

subscribe(connection, request, subscription_id)

View Source
@spec subscribe(pid() | String.t(), map(), String.t()) :: :ok | {:error, term()}

Subscribe to a channel on this connection.

Link to this function

unsubscribe(connection, subscription_id)

View Source
@spec unsubscribe(pid() | String.t(), String.t()) :: :ok

Unsubscribe from a channel.