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

Mapping of coin symbols to mid prices.

This endpoint returns a dynamic map where keys are coin symbols (e.g., "BTC", "ETH") and values are mid prices as strings.

See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-mids-for-all-coins

Usage

{:ok, all_mids} = AllMids.request()
{:ok, price} = AllMids.get_mid(all_mids, "BTC")
# => {:ok, "43250.5"}

# Or with bang variant
all_mids = AllMids.request!()

Summary

Functions

Returns metadata about this endpoint.

Returns postgres table configurations (multi-table support).

Returns storage configuration for this endpoint.

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 all mids data.

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

Get all coin symbols.

Get the mid price for a specific coin.

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.

Returns true if any storage backend is enabled.

Convert the mids map to a list of {coin, price} tuples.

Types

@type t() :: %Hyperliquid.Api.Info.AllMids{
  dex: String.t() | nil,
  mids: %{required(String.t()) => String.t()}
}

Functions

Returns metadata about this endpoint.

Example

iex> Hyperliquid.Api.Info.AllMids.__endpoint_info__()
%{
  endpoint: "allMids",
  type: :info,
  rate_limit_cost: 2,
  params: [],
  optional_params: [:dex],
  doc: "Retrieve mid prices for all actively traded coins",
  returns: "Map of coin symbols to mid prices as strings"
}

Returns postgres table configurations (multi-table support).

Returns storage configuration for this endpoint.

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

Link to this function

build_request(opts \\ [])

View Source
@spec build_request(keyword()) :: map()

Build the request payload.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Link to this function

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

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

Creates a changeset for all mids data.

Parameters

  • all_mids: The all mids struct
  • attrs: Map of coin symbols to mid prices

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

@spec get_coins(t()) :: [String.t()]

Get all coin symbols.

Example

iex> get_coins(%AllMids{mids: %{"BTC" => "43250.5", "ETH" => "2280.75"}})
["BTC", "ETH"]
@spec get_mid(t(), String.t()) :: {:ok, String.t()} | {:error, :not_found}

Get the mid price for a specific coin.

Example

iex> get_mid(%AllMids{mids: %{"BTC" => "43250.5"}}, "BTC")
{:ok, "43250.5"}

iex> get_mid(%AllMids{mids: %{"BTC" => "43250.5"}}, "DOGE")
{:error, :not_found}
@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(keyword()) :: {:ok, t()} | {:error, term()}

Make the API request and parse the response.

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

Make the API request, raising on error.

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

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

Link to this function

request_raw!(opts \\ [])

View Source
@spec request_raw!(keyword()) :: map()

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

Returns true if any storage backend is enabled.

@spec to_list(t()) :: [{String.t(), String.t()}]

Convert the mids map to a list of {coin, price} tuples.

Example

iex> to_list(%AllMids{mids: %{"BTC" => "43250.5", "ETH" => "2280.75"}})
[{"BTC", "43250.5"}, {"ETH", "2280.75"}]