Tracks Deribit-dialect JSON-RPC subscriptions for reconnect restoration.
Only public/subscribe and public/unsubscribe with params.channels are
auto-tracked (plus their id-keyed confirmations and rejections). Other
venues' subscribe shapes are ignored and are not automatically restored;
build_restore_message/1 always emits Deribit's payload.
Client.subscribe/2 sends no JSON-RPC id, so channels are recorded at send
time. A server-side rejection leaves them in the restore set. Id-carrying
requests wait for a result or error.
Pure functional module — state ownership stays with Client GenServer.
Telemetry Events
The following telemetry events are emitted:
[:zen_websocket, :subscription_manager, :add]- Emitted when a channel is added.- Measurements:
%{count: 1} - Metadata:
%{channel: channel}
- Measurements:
[:zen_websocket, :subscription_manager, :remove]- Emitted when a channel is removed.- Measurements:
%{count: 1} - Metadata:
%{channel: channel}
- Measurements:
[:zen_websocket, :subscription_manager, :restore]- Emitted when subscriptions are restored.- Measurements:
%{channel_count: integer()} - Metadata:
%{channels: [String.t()]}
- Measurements:
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
handle_message | 2 | Track Deribit public/subscribe and public/unsubscribe requests and confirmations. | msg: value, state: value |
build_restore_message | 1 | Build a restore message for reconnection. | state: value |
list | 1 | List all currently tracked subscriptions. | state: value |
remove | 2 | Remove a channel from the tracked subscription set. | state: value, channel: value |
add | 2 | Add a channel to the tracked subscription set. | state: value, channel: value |
Summary
Functions
Adds a channel to the tracked subscription set.
Builds a restore message for reconnection.
Tracks Deribit public/subscribe and public/unsubscribe requests.
Lists all currently tracked subscriptions.
Removes a channel from the tracked subscription set.
Types
Functions
Adds a channel to the tracked subscription set.
Used after a subscribe operation is confirmed or when it has no correlation ID.
Builds a restore message for reconnection.
Returns nil if:
- No subscriptions to restore
restore_subscriptionsconfig is false
Returns JSON-encoded subscribe message otherwise.
Tracks Deribit public/subscribe and public/unsubscribe requests.
Requests with no id (including Client.subscribe/2) apply immediately.
Id-carrying requests wait for a result or error. Data ticks and non-Deribit
subscribe shapes are ignored.
Lists all currently tracked subscriptions.
Removes a channel from the tracked subscription set.
Used after an unsubscribe operation is confirmed or when it has no correlation ID.