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

Recent trades for a coin.

Returns a list of recent trades with price, size, side, and timestamp.

See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint

Usage

{:ok, trades} = RecentTrades.request("BTC")
{:ok, vwap} = RecentTrades.vwap(trades)

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.

Get buy trades only.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Creates a changeset for recent trades data.

Fetch data and persist to configured storage backends.

Fetch data and persist. Raises on error.

Get trades within a time range.

Get the latest trade.

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 sell trades only.

Returns true if any storage backend is enabled.

Calculate total volume.

Calculate VWAP (Volume Weighted Average Price).

Types

@type t() :: %Hyperliquid.Api.Info.RecentTrades{coin: String.t(), trades: [Trade.t()]}

Functions

Returns metadata about this endpoint.

Example

iex> Hyperliquid.Api.Info.RecentTrades.__endpoint_info__()
%{
  endpoint: "recentTrades",
  type: :info,
  rate_limit_cost: 1,
  params: [:coin],
  optional_params: [],
  doc: "Retrieve recent trades for a coin",
  returns: "List of recent trades with price, size, side, and timestamp"
}

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(term()) :: map()

Build the request payload.

@spec buys(t()) :: [map()]

Get buy trades only.

Parameters

  • recent: The recent trades struct

Returns

  • List of buy trades

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Link to this function

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

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

Creates a changeset for recent trades data.

Parameters

  • recent: The recent trades struct
  • attrs: Map with trades key

Returns

  • Ecto.Changeset.t()

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.

Fetch data and persist. Raises on error.

Link to this function

in_range(recent_trades, start_time, end_time)

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

Get trades within a time range.

Parameters

  • recent: The recent trades struct
  • start_time: Start timestamp in ms
  • end_time: End timestamp in ms

Returns

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

Get the latest trade.

Parameters

  • recent: The recent trades struct

Returns

  • {:ok, Trade.t()} if trades exist
  • {:error, :empty} if no trades
@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 sells(t()) :: [map()]

Get sell trades only.

Parameters

  • recent: The recent trades struct

Returns

  • List of sell trades

Returns true if any storage backend is enabled.

Link to this function

total_volume(recent_trades)

View Source
@spec total_volume(t()) :: {:ok, float()} | {:error, :empty}

Calculate total volume.

Parameters

  • recent: The recent trades struct

Returns

  • {:ok, float()} - Total volume
  • {:error, :empty} - No trades
@spec vwap(t()) :: {:ok, float()} | {:error, :empty}

Calculate VWAP (Volume Weighted Average Price).

Parameters

  • recent: The recent trades struct

Returns

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