View Source Hyperliquid.Storage.Writer (hyperliquid v0.2.2)

Writes subscription events to configured storage backends.

Events are buffered and flushed periodically for efficiency. This GenServer provides both async (fire-and-forget) and sync (blocking) storage operations.

Usage

# Queue an event for async storage (recommended for high-throughput)
Writer.store_async(Hyperliquid.Api.Subscription.Trades, event_data)

# Store an event synchronously (for critical data)
{:ok, :stored} = Writer.store_sync(module, event_data)

Configuration

The writer respects storage configuration defined in each subscription module via the storage option in use Hyperliquid.Api.SubscriptionEndpoint.

Summary

Functions

Get current buffer size.

Returns a specification to start this module under a supervisor.

Force an immediate flush of the buffer.

Start the storage writer.

Queue an event for async storage.

Store an event synchronously.

Types

@type event_entry() :: {module(), map(), integer()}

Functions

@spec buffer_size() :: non_neg_integer()

Get current buffer size.

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec flush() :: :ok

Force an immediate flush of the buffer.

Start the storage writer.

Options

  • :flush_interval - Milliseconds between flushes (default: 5000)
  • :buffer_size - Max events before forcing flush (default: 100)
Link to this function

store_async(module, event_data)

View Source
@spec store_async(module(), map()) :: :ok

Queue an event for async storage.

This is non-blocking and batches writes for efficiency.

Link to this function

store_sync(module, event_data)

View Source
@spec store_sync(module(), map()) :: {:ok, :stored} | {:error, term()}

Store an event synchronously.

This blocks until the event is written to all configured backends.