Simple batch subscription manager for efficiently subscribing to multiple channels.
Prevents overwhelming the API by batching subscription requests with configurable batch size and delay between batches.
Summary
Functions
Cancels a batch subscription request.
Returns a specification to start this module under a supervisor.
Gets the status of all batch requests.
Gets the status of a batch subscription request.
Starts the batch subscription manager.
Subscribes to multiple channels in batches.
Types
@type batch_status() :: %{ completed: non_neg_integer(), pending: non_neg_integer(), total: non_neg_integer(), failed: boolean(), error: term() | nil }
Functions
Cancels a batch subscription request.
Parameters
manager- The batch manager processrequest_id- The request ID to cancel
Returns
:okif cancelled successfully{:error, :not_found}if request_id is invalid
Returns a specification to start this module under a supervisor.
See Supervisor.
Gets the status of all batch requests.
Returns
{:ok, statuses} where statuses is a map of request_id => status.
@spec get_status(pid(), String.t()) :: {:ok, batch_status()} | {:error, :not_found}
Gets the status of a batch subscription request.
Parameters
manager- The batch manager processrequest_id- The request ID returned by subscribe_batch/2
Returns
{:ok, status}with completed/pending/total counts{:error, :not_found}if request_id is invalid
@spec start_link(keyword()) :: GenServer.on_start()
Starts the batch subscription manager.
Options
:adapter- The Deribit adapter process (required):batch_size- Number of channels per batch (default: 10):batch_delay- Delay between batches in ms (default: 200)
Returns
{:ok, pid} on success.
Subscribes to multiple channels in batches.
Parameters
manager- The batch manager processchannels- List of channel names to subscribe to
Returns
{:ok, request_id} where request_id can be used to track progress.