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

User portfolio performance data.

Returns historical account value, PnL, and volume data across multiple timeframes (day, week, month, allTime) for both combined and perp-only views.

See: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#query-a-users-portfolio

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 portfolio data.

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

Get data for a specific period.

Get the latest account value for a period.

Get the latest PnL for a period.

Parse and validate the API response.

Get all available period names.

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 volume for a period.

Types

@type t() :: %Hyperliquid.Api.Info.Portfolio{periods: [Period.t()]}

Functions

Returns metadata about this endpoint.

Example

iex> Hyperliquid.Api.Info.Portfolio.__endpoint_info__()
%{
  endpoint: "portfolio",
  type: :info,
  rate_limit_cost: 2,
  params: [:user],
  optional_params: [],
  doc: "Retrieve user portfolio performance data",
  returns: "Historical account value, PnL, and volume data"
}

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.

Returns true if cache storage is enabled.

Returns the cache TTL if configured.

Link to this function

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

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

Creates a changeset for portfolio data.

Parameters

  • portfolio: The portfolio struct
  • attrs: Map with periods key

Returns

  • Ecto.Changeset.t()

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

Link to this function

get_period(portfolio, period_name)

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

Get data for a specific period.

Parameters

  • portfolio: The portfolio struct
  • period_name: Period name (e.g., "day", "week", "month", "allTime", "perpDay", etc.)

Returns

  • {:ok, PeriodData.t()} if found
  • {:error, :not_found} if not found
Link to this function

latest_account_value(portfolio, period_name)

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

Get the latest account value for a period.

Parameters

  • portfolio: The portfolio struct
  • period_name: Period name

Returns

  • {:ok, String.t()} if found
  • {:error, :not_found} if not found or no history
Link to this function

latest_pnl(portfolio, period_name)

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

Get the latest PnL for a period.

Parameters

  • portfolio: The portfolio struct
  • period_name: Period name

Returns

  • {:ok, String.t()} if found
  • {:error, :not_found} if not found or no history
@spec parse_response(map()) :: {:ok, t()} | {:error, term()}

Parse and validate the API response.

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

Get all available period names.

Parameters

  • portfolio: The portfolio struct

Returns

  • List of period names

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.

Returns true if any storage backend is enabled.

Link to this function

volume(portfolio, period_name)

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

Get volume for a period.

Parameters

  • portfolio: The portfolio struct
  • period_name: Period name

Returns

  • {:ok, String.t()} if found
  • {:error, :not_found} if not found