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

OHLCV candle data for a coin.

Returns historical candle data for charting and technical analysis.

See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-candlestick-snapshot

Usage

{:ok, candles} = CandleSnapshot.request("BTC", "1h", start_time, end_time)
{:ok, vwap} = CandleSnapshot.vwap(candles)

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.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Creates a changeset for candle snapshot data.

Fetch data and persist to configured storage backends.

Fetch data and persist. Raises on error.

Get candles within a time range.

Get the latest candle.

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.

Get valid candle intervals.

Calculate VWAP (Volume Weighted Average Price) for the snapshot.

Types

@type t() :: %Hyperliquid.Api.Info.CandleSnapshot{
  candles: [Candle.t()],
  coin: String.t() | nil,
  interval: String.t() | nil
}

Functions

Returns metadata about this endpoint.

Example

iex> Hyperliquid.Api.Info.CandleSnapshot.__endpoint_info__()
%{
  endpoint: "candleSnapshot",
  type: :info,
  rate_limit_cost: 2,
  params: [:coin, :interval, :start_time, :end_time],
  optional_params: [],
  doc: "Retrieve OHLCV candle data for a coin",
  returns: "Array of candles with OHLCV data and trade counts"
}

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(coin, interval, start_time, end_time)

View Source
@spec build_request(term(), term(), term(), term()) :: map()

Build the request payload.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Link to this function

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

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

Creates a changeset for candle snapshot data.

Parameters

  • snapshot: The snapshot struct
  • attrs: Map with candles key

Returns

  • Ecto.Changeset.t()
Link to this function

fetch(coin, interval, start_time, end_time)

View Source

Fetch data and persist to configured storage backends.

This calls request/N and then stores the result using Storage.Writer. Request params are merged into stored data for cache key generation.

Link to this function

fetch!(coin, interval, start_time, end_time)

View Source

Fetch data and persist. Raises on error.

Link to this function

in_range(candle_snapshot, start_time, end_time)

View Source
@spec in_range(t(), non_neg_integer(), non_neg_integer()) :: [map()]

Get candles within a time range.

Parameters

  • snapshot: The candle snapshot struct
  • start_time: Start timestamp in ms
  • end_time: End timestamp in ms

Returns

  • List of candles within range
@spec latest(t()) :: {:ok, map()} | {:error, :empty}

Get the latest candle.

Parameters

  • snapshot: The candle snapshot struct

Returns

  • {:ok, Candle.t()} if candles exist
  • {:error, :empty} if no candles
@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.

Link to this function

request(coin, interval, start_time, end_time)

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

Make the API request and parse the response.

Link to this function

request!(coin, interval, start_time, end_time)

View Source
@spec request!(term(), term(), term(), term()) :: t()

Make the API request, raising on error.

Link to this function

request_raw(coin, interval, start_time, end_time)

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

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

Link to this function

request_raw!(coin, interval, start_time, end_time)

View Source
@spec request_raw!(term(), term(), term(), term()) :: map()

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

Returns true if any storage backend is enabled.

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

Get valid candle intervals.

Returns

  • List of valid interval strings
@spec vwap(t()) :: {:ok, float()} | {:error, :empty}

Calculate VWAP (Volume Weighted Average Price) for the snapshot.

Parameters

  • snapshot: The candle snapshot struct

Returns

  • {:ok, float()} - VWAP value
  • {:error, :empty} - No candles