View Source Hyperliquid.Api.Info.OutcomeTemplates (hyperliquid v0.3.0)

Templates that HIP-4 outcome deployers instantiate.

Every deployer-created prediction market comes from a template. A template fixes display name and description text containing {keyword} placeholders, together with a typed hint per keyword; an instantiation supplies exactly one value per keyword.

See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-4-deployer-actions

Usage

{:ok, templates} = OutcomeTemplates.request()
{:ok, template} = OutcomeTemplates.find(templates, "some-template-id")

Summary

Types

Value format required for a template keyword.

t()

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 outcome templates.

Fetch data and persist to configured storage backends.

Fetch data and persist. Raises on error.

Find a template by id.

List the keyword names a template requires, in the order the API returned them.

Build the sorted keywordToValue list required by the deploy actions.

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.

Types

@type keyword_hint() :: String.t()

Value format required for a template keyword.

  • "dateTime" - %Y%m%d-%H%M, within the next year (e.g. 20260712-1830)
  • "date" - YYYYMMDD, end of day, within the next year (e.g. 20260712)
  • "string" - free text
  • "hlPerp" - coin name of an existing perp (e.g. ABC or test:ABC)
@type t() :: %Hyperliquid.Api.Info.OutcomeTemplates{templates: [map()]}

Functions

Returns metadata about this endpoint.

Example

iex> Hyperliquid.Api.Info.OutcomeTemplates.__endpoint_info__()
%{
  endpoint: "outcomeTemplates",
  type: :info,
  rate_limit_cost: 2,
  params: [],
  optional_params: [],
  doc: "Retrieve HIP-4 outcome templates",
  returns: "Templates that outcome deployers instantiate"
}

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.

@spec build_request() :: map()

Build the request payload.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Link to this function

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

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

Creates a changeset for outcome templates.

Parameters

  • templates: The templates struct
  • attrs: Map with a templates key

Returns

  • Ecto.Changeset.t()
@spec fetch() :: {:ok, t()} | {:error, term()}

Fetch data and persist to configured storage backends.

This calls request/0 and then stores the result using Storage.Writer.

@spec fetch!() :: t()

Fetch data and persist. Raises on error.

Link to this function

find(outcome_templates, id)

View Source
@spec find(t(), String.t()) :: {:ok, map()} | {:error, :not_found}

Find a template by id.

Parameters

  • templates: The templates struct
  • id: Template identifier

Returns

  • {:ok, template} if found
  • {:error, :not_found} otherwise
@spec keyword_names(map()) :: [String.t()]

List the keyword names a template requires, in the order the API returned them.

keywordToValue must be sorted lexicographically before signing, so use keyword_names/1 to discover the keywords and sort your own pairs.

Parameters

  • template: A template from the response

Returns

  • List of keyword names
Link to this function

keyword_to_value(values)

View Source
@spec keyword_to_value(map() | keyword()) :: [[String.t()]]

Build the sorted keywordToValue list required by the deploy actions.

The exchange requires lists of tuples to be lexicographically sorted before signing.

Parameters

  • values: Map or keyword list of keyword name to value

Returns

  • Sorted list of [keyword, value] pairs

Examples

iex> Hyperliquid.Api.Info.OutcomeTemplates.keyword_to_value(%{
...>   "underlying" => "ABC",
...>   "expiry" => "20260801-0600",
...>   "target" => "100"
...> })
[["expiry", "20260801-0600"], ["target", "100"], ["underlying", "ABC"]]
@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() :: {:ok, t()} | {:error, term()}

Make the API request and parse the response.

@spec request!() :: t()

Make the API request, raising on error.

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

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

@spec request_raw!() :: map()

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

Returns true if any storage backend is enabled.