WebsockexAdapter.Examples.DeribitGenServerAdapter (WebsockexAdapter v0.1.1)
View SourceProduction-ready supervised Deribit adapter with automatic reconnection.
Features: Monitor WebSocket client, auto-reconnect, restore auth/subscriptions. Only 5 public functions for clean API. See DeribitRpc for available methods.
Summary
Functions
Authenticates with Deribit using configured credentials.
Returns a specification to start this module under a supervisor.
Returns the current adapter state.
Sends a JSON-RPC request to Deribit.
Starts the Deribit adapter GenServer.
Subscribes to Deribit channels for real-time data.
Types
Functions
@spec authenticate(GenServer.server()) :: :ok | {:error, atom()}
Authenticates with Deribit using configured credentials.
Returns
:ok
on successful authentication{:error, :not_connected}
if not connected{:error, :missing_credentials}
if credentials not configured
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec get_state(GenServer.server()) :: {:ok, state()}
Returns the current adapter state.
Returns
{:ok, state}
with the internal state map.
@spec send_request(GenServer.server(), String.t(), map()) :: {:ok, map()} | {:error, atom()}
Sends a JSON-RPC request to Deribit.
Parameters
adapter
- The adapter GenServermethod
- RPC method nameparams
- Method parameters (default: %{})
Returns
The response from Deribit or {:error, :not_connected}
.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the Deribit adapter GenServer.
Options
:name
- GenServer name (required):client_id
- Deribit API client ID:client_secret
- Deribit API client secret:url
- WebSocket URL (defaults to test.deribit.com):heartbeat_interval
- Heartbeat interval in seconds:handler
- Optional message handler module
Returns
{:ok, pid}
on success.
@spec subscribe(GenServer.server(), [String.t()]) :: :ok | {:error, atom()}
Subscribes to Deribit channels for real-time data.
Parameters
adapter
- The adapter GenServerchannels
- List of channel names
Returns
:ok
on successful subscription{:error, :not_connected}
if not connected