DeribitEx.ResubscriptionHandler (deribit_ex v0.1.0)
View SourceHandles automatic resubscription to channels after token changes.
This module is responsible for:
- Tracking channels that need to be resubscribed after token changes
- Providing a mechanism to resubscribe to channels automatically
- Handling both public and private channel resubscriptions
- Managing resubscription failures and retries
Integrates with the Adapter and Client to ensure subscriptions are maintained during token operations.
Summary
Functions
Notifies the resubscription handler of a session transition.
Determines if a channel requires authentication.
Creates a new resubscription handler state.
Performs resubscription for all tracked channels.
Registers a channel subscription for potential resubscription.
Performs token-aware subscription to a channel.
Removes a channel subscription from tracking.
Types
@type t() :: %DeribitEx.ResubscriptionHandler{ active_session_id: String.t() | nil, channels: %{optional(String.t()) => map()}, max_retries: non_neg_integer(), resubscribe_after_auth: boolean(), resubscription_in_progress: boolean(), retry_count: non_neg_integer() }
Represents channel resubscription state tracking.
channels
: Map of channel name to subscription parametersactive_session_id
: ID of the currently active sessionresubscription_in_progress
: Flag to track when resubscription is happeningresubscribe_after_auth
: Flag to indicate resubscription needed after authenticationretry_count
: Counter for resubscription attemptsmax_retries
: Maximum number of resubscription retries
Functions
@spec handle_session_transition( t(), DeribitEx.SessionContext.t(), DeribitEx.SessionContext.t() ) :: {:ok, t()}
Notifies the resubscription handler of a session transition.
Parameters
state
: Current resubscription stateprev_session
: Previous sessionnew_session
: New session after token change
Returns
{:ok, updated_state}
: Updated state with resubscription flag set
Determines if a channel requires authentication.
Parameters
channel
: Channel name to check
Returns
true
if the channel is private (requires authentication)false
if the channel is public
Creates a new resubscription handler state.
Parameters
opts
: Options for the handler:max_retries
- Maximum resubscription retry attempts (default: 3)
Returns
- A new empty resubscription state
Performs resubscription for all tracked channels.
Should be called after authentication completes with a new token.
Parameters
state
: Current resubscription stateconn
: WebsockexNova client connection
Returns
{:ok, updated_state, results}
: Updated state and resubscription results{:error, reason, state}
: Error information if resubscription fails
Registers a channel subscription for potential resubscription.
Parameters
state
: Current resubscription statechannel
: Channel name or topicparams
: Subscription parameters used for this channelsession_id
: ID of the session that created the subscription
Returns
{:ok, updated_state}
: Updated state with the registered channel
@spec subscribe_to_channel(pid(), String.t(), map() | nil) :: {:ok, map() | String.t()} | {:error, any()}
Performs token-aware subscription to a channel.
Parameters
conn
: WebsockexNova client connectionchannel
: Channel to subscribe toparams
: Subscription parameters
Returns
{:ok, subscription}
: Successful subscription{:error, reason}
: If subscription fails
Removes a channel subscription from tracking.
Parameters
state
: Current resubscription statechannel
: Channel to unregister
Returns
{:ok, updated_state}
: Updated state without the channel