View Source Hyperliquid.Api.Info.L2Book (hyperliquid v0.2.2)

L2 order book snapshot for a coin.

Returns bid and ask levels with prices and sizes.

See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-order-book

Usage

{:ok, book} = L2Book.request("BTC")
{:ok, mid} = L2Book.mid_price(book)
# => {:ok, 50000.5}

# Or with bang variant
book = L2Book.request!("BTC")

Summary

Functions

Returns metadata about this endpoint.

Returns postgres table configurations (multi-table support).

Returns storage configuration for this endpoint.

Get best ask price.

Get best bid price.

Build a cache key from response data using the configured pattern. Returns nil if cache is not enabled or no pattern configured.

Build the request payload.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Creates a changeset for L2 book data.

Fetch is an alias for request when no storage is configured.

Get mid price.

Parse and validate the API response.

Returns true if postgres storage is enabled.

Returns the postgres table name if configured (primary table for legacy support).

Returns the upsert config for postgres (primary table for legacy support).

Get the rate limit cost for this endpoint.

Make the API request and parse the response.

Make the API request, raising on error.

Make the API request and return the raw response map (no key transformation).

Make the API request returning raw map, raising on error.

Get spread.

Returns true if any storage backend is enabled.

Types

@type t() :: %Hyperliquid.Api.Info.L2Book{
  coin: String.t(),
  levels: [Level.t()],
  time: non_neg_integer()
}

Functions

Returns metadata about this endpoint.

Example

iex> Hyperliquid.Api.Info.L2Book.__endpoint_info__()
%{
  endpoint: "l2Book",
  type: :info,
  rate_limit_cost: 2,
  params: [:coin],
  optional_params: [],
  doc: "Retrieve L2 order book snapshot for a coin",
  returns: "Order book with bids/asks arrays containing price, size, and order count"
}

Returns postgres table configurations (multi-table support).

Returns storage configuration for this endpoint.

@spec best_ask(t()) :: {:ok, String.t()} | {:error, :empty}

Get best ask price.

@spec best_bid(t()) :: {:ok, String.t()} | {:error, :empty}

Get best bid price.

Build a cache key from response data using the configured pattern. Returns nil if cache is not enabled or no pattern configured.

@spec build_request(term()) :: map()

Build the request payload.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Link to this function

changeset(book \\ %__MODULE__{}, attrs)

View Source
@spec changeset(t(), map()) :: Ecto.Changeset.t()

Creates a changeset for L2 book data.

Fetch is an alias for request when no storage is configured.

@spec mid_price(t()) :: {:ok, float()} | {:error, :empty}

Get mid price.

@spec parse_response(map()) :: {:ok, t()} | {:error, term()}

Parse and validate the API response.

Returns true if postgres storage is enabled.

Returns the postgres table name if configured (primary table for legacy support).

Link to this function

postgres_upsert_config()

View Source

Returns the upsert config for postgres (primary table for legacy support).

@spec rate_limit_cost() :: non_neg_integer()

Get the rate limit cost for this endpoint.

@spec request(term()) :: {:ok, t()} | {:error, term()}

Make the API request and parse the response.

@spec request!(term()) :: t()

Make the API request, raising on error.

@spec request_raw(term()) :: {:ok, map()} | {:error, term()}

Make the API request and return the raw response map (no key transformation).

@spec request_raw!(term()) :: map()

Make the API request returning raw map, raising on error.

@spec spread(t()) :: {:ok, float()} | {:error, :empty}

Get spread.

Returns true if any storage backend is enabled.