View Source Hyperliquid.Transport.Http (hyperliquid v0.2.2)

HTTP transport layer for Hyperliquid API.

Provides low-level HTTP communication with the Hyperliquid Info and Exchange APIs. Uses HTTPoison for HTTP requests with automatic JSON encoding/decoding and camelCase to snake_case transformation.

Usage

# Info API request (no auth needed)
{:ok, response} = Http.info_request(%{type: "allMids"})

# Exchange API request (requires signature)
{:ok, response} = Http.exchange_request(action, signature, nonce)

# Raw POST request
{:ok, response} = Http.post("/info", %{type: "meta"})

Configuration

The HTTP transport uses Hyperliquid.Config for URL configuration:

  • Config.api_base/0 - Base URL for API requests
  • Config.mainnet?/0 - Whether to use mainnet or testnet

Summary

Functions

Fetch active asset data for a user and coin.

Fetch aligned quote token info.

Fetch all mid prices.

Fetch all mid prices. Raises on error.

Fetch perpetuals metadata for a specific DEX.

Fetch user's perpetuals clearinghouse state.

Fetch user's perpetuals clearinghouse state. Raises on error.

Fetch user's delegations.

Fetch user's delegator history.

Fetch user's delegator rewards.

Fetch user's delegator summary.

Fetch exchange status.

Fetch exchange status. Raises on error.

Make a request to the Explorer API.

Fetch user's extra agents.

Fetch user's extra agents. Raises on error.

Fetch user's open orders with frontend info.

Fetch user's open orders with frontend info. Raises on error.

Fetch funding history for a user. Raises on error.

Make a GET request.

Fetch gossip network root IPs.

Fetch user's historical orders.

Fetch user's historical orders. Raises on error.

Make a request to the Info API.

Check if user is a VIP.

Fetch L2 order book snapshot.

Fetch L2 order book snapshot. Raises on error.

Fetch leaderboard data from the stats API.

Fetch leaderboard data from the stats API. Raises on error.

Fetch perpetuals metadata.

Fetch perpetuals metadata. Raises on error.

Fetch perpetuals metadata with asset contexts.

Fetch perpetuals metadata with asset contexts. Raises on error.

Fetch user's open orders.

Fetch user's open orders. Raises on error.

Fetch perpetual deploy auction status.

Fetch limits for a specific perpetual DEX.

Fetch all perpetual DEXs.

Fetch all perpetual DEXs. Raises on error.

Fetch list of perpetuals at their open interest cap.

Fetch user's portfolio performance data.

Fetch user's portfolio performance data. Raises on error.

Make a raw POST request to any endpoint.

Fetch predicted funding rates.

Fetch predicted funding rates. Raises on error.

Fetch recent trades for a coin.

Fetch recent trades for a coin. Raises on error.

Fetch user's referral information.

Fetch user's referral information. Raises on error.

Fetch user's spot clearinghouse state.

Fetch user's spot clearinghouse state. Raises on error.

Fetch spot metadata.

Fetch spot metadata. Raises on error.

Fetch spot metadata with asset contexts.

Fetch spot metadata with asset contexts. Raises on error.

Make a request to the Stats API.

Fetch transaction details from the explorer.

Fetch user details from the explorer.

Fetch user's order history.

Fetch user's order history. Raises on error.

Make a user-signed (EIP-712) exchange request.

Fetch vaults data from the stats API.

Fetch vaults data from the stats API. Raises on error.

Types

@type request_opts() :: [
  timeout: non_neg_integer(),
  recv_timeout: non_neg_integer(),
  raw: boolean()
]
@type response() :: {:ok, map() | list()} | {:error, Hyperliquid.Error.t()}

Functions

Link to this function

active_asset_data(user, coin, opts \\ [])

View Source
@spec active_asset_data(String.t(), String.t(), request_opts()) :: response()

Fetch active asset data for a user and coin.

Parameters

  • user: User address (0x...)
  • coin: Coin symbol (e.g., "BTC")
  • opts: Optional HTTPoison options

Returns

  • {:ok, data} - Active asset data with leverage and limits
  • {:error, %Error{}} - Error with details
Link to this function

aligned_quote_token_info(token, opts \\ [])

View Source
@spec aligned_quote_token_info(non_neg_integer(), request_opts()) :: response()

Fetch aligned quote token info.

Parameters

  • token: Token index
  • opts: Optional HTTPoison options

Returns

  • {:ok, info} - Token alignment info
  • {:error, %Error{}} - Error with details
@spec all_mids(request_opts()) :: response()

Fetch all mid prices.

Returns

  • {:ok, %{"BTC" => "43250.5", ...}} - Map of coin to mid price
  • {:error, %Error{}} - Error with details

Example

{:ok, mids} = Http.all_mids()
mids["BTC"]
# => "43250.5"

Fetch all mid prices. Raises on error.

Link to this function

all_perp_metas(dex \\ nil, opts \\ [])

View Source
@spec all_perp_metas(String.t() | nil, request_opts()) :: response()

Fetch perpetuals metadata for a specific DEX.

Parameters

  • dex: Optional DEX name (defaults to empty string for all)
  • opts: Optional HTTPoison options

Returns

  • {:ok, meta} - Perpetuals metadata
  • {:error, %Error{}} - Error with details
Link to this function

block_details(height \\ nil, opts \\ [])

View Source
@spec block_details(non_neg_integer() | nil, request_opts()) :: response()

Fetch block details.

Parameters

  • height: Optional block height (nil for latest)
  • opts: Optional HTTPoison options

Returns

  • {:ok, block} - Block details
  • {:error, %Error{}} - Error with details
Link to this function

candles(coin, interval, start_time, end_time, opts \\ [])

View Source

Fetch candle data.

Parameters

  • coin: Coin symbol
  • interval: Candle interval (e.g., "1m", "1h", "1d")
  • start_time: Start timestamp in ms
  • end_time: End timestamp in ms
  • opts: Optional HTTPoison options

Returns

  • {:ok, candles} - List of candle data
  • {:error, %Error{}} - Error with details
Link to this function

candles!(coin, interval, start_time, end_time, opts \\ [])

View Source

Fetch candle data. Raises on error.

Link to this function

clearinghouse_state(user, opts \\ [])

View Source
@spec clearinghouse_state(String.t(), request_opts()) :: response()

Fetch user's perpetuals clearinghouse state.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, state} - Clearinghouse state with positions
  • {:error, %Error{}} - Error with details
Link to this function

clearinghouse_state!(user, opts \\ [])

View Source

Fetch user's perpetuals clearinghouse state. Raises on error.

Link to this function

delegations(user, opts \\ [])

View Source
@spec delegations(String.t(), request_opts()) :: response()

Fetch user's delegations.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, delegations} - List of delegations
  • {:error, %Error{}} - Error with details
Link to this function

delegator_history(user, opts \\ [])

View Source
@spec delegator_history(String.t(), request_opts()) :: response()

Fetch user's delegator history.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, history} - Delegation history
  • {:error, %Error{}} - Error with details
Link to this function

delegator_rewards(user, opts \\ [])

View Source
@spec delegator_rewards(String.t(), request_opts()) :: response()

Fetch user's delegator rewards.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, rewards} - Delegation rewards
  • {:error, %Error{}} - Error with details
Link to this function

delegator_summary(user, opts \\ [])

View Source
@spec delegator_summary(String.t(), request_opts()) :: response()

Fetch user's delegator summary.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, summary} - Delegator summary
  • {:error, %Error{}} - Error with details
Link to this function

exchange_request(action, signature, nonce, vault_address \\ nil, expires_after \\ nil, opts \\ [])

View Source
@spec exchange_request(
  map(),
  map(),
  non_neg_integer(),
  String.t() | nil,
  non_neg_integer() | nil,
  request_opts()
) :: response()

Make a request to the Exchange API.

The Exchange API is used for trading operations and requires EIP-712 signatures.

Parameters

  • action: The action map (order, cancel, etc.)
  • signature: EIP-712 signature
  • nonce: Timestamp nonce
  • vault_address: Optional vault address
  • opts: Optional HTTPoison options

Returns

  • {:ok, response} - Parsed JSON response (snake_cased)
  • {:error, %Error{}} - Error with details

Examples

{:ok, result} = Http.exchange_request(
  %{type: "order", orders: [...], grouping: "na"},
  signature,
  nonce
)
Link to this function

exchange_status(opts \\ [])

View Source
@spec exchange_status(request_opts()) :: response()

Fetch exchange status.

Returns

  • {:ok, status} - Exchange operational status
  • {:error, %Error{}} - Error with details
Link to this function

exchange_status!(opts \\ [])

View Source

Fetch exchange status. Raises on error.

Link to this function

explorer_request(payload, opts \\ [])

View Source
@spec explorer_request(map(), request_opts()) :: response()

Make a request to the Explorer API.

Used for block_details, user_details, and tx_details endpoints.

Parameters

  • payload: Map with request type and parameters
  • opts: Optional HTTPoison options

Returns

  • {:ok, response} - Parsed JSON response (snake_cased)
  • {:error, %Error{}} - Error with details

Examples

# Get block details
{:ok, block} = Http.explorer_request(%{type: "blockDetails", height: 12345})

# Get transaction details
{:ok, tx} = Http.explorer_request(%{type: "txDetails", hash: "0x..."})
Link to this function

extra_agents(user, opts \\ [])

View Source
@spec extra_agents(String.t(), request_opts()) :: response()

Fetch user's extra agents.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, agents} - List of extra agents
  • {:error, %Error{}} - Error with details
Link to this function

extra_agents!(user, opts \\ [])

View Source

Fetch user's extra agents. Raises on error.

Link to this function

frontend_open_orders(user, opts \\ [])

View Source
@spec frontend_open_orders(String.t(), request_opts()) :: response()

Fetch user's open orders with frontend info.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, orders} - Open orders with frontend display info
  • {:error, %Error{}} - Error with details
Link to this function

frontend_open_orders!(user, opts \\ [])

View Source

Fetch user's open orders with frontend info. Raises on error.

Link to this function

funding_history(user, start_time, end_time \\ nil, opts \\ [])

View Source
@spec funding_history(
  String.t(),
  non_neg_integer(),
  non_neg_integer() | nil,
  request_opts()
) ::
  response()

Fetch funding history for a user.

Parameters

  • user: User address (0x...)
  • start_time: Start timestamp in ms
  • end_time: Optional end timestamp in ms
  • opts: Optional HTTPoison options

Returns

  • {:ok, funding} - Funding history
  • {:error, %Error{}} - Error with details
Link to this function

funding_history!(user, start_time, end_time \\ nil, opts \\ [])

View Source

Fetch funding history for a user. Raises on error.

@spec get(String.t(), request_opts()) :: response()

Make a GET request.

Parameters

  • url: Full URL or path (will be appended to api_base if relative)
  • opts: Optional HTTPoison options

Returns

  • {:ok, response} - Parsed JSON response (snake_cased)
  • {:error, %Error{}} - Error with details
Link to this function

gossip_root_ips(opts \\ [])

View Source
@spec gossip_root_ips(request_opts()) :: response()

Fetch gossip network root IPs.

Returns

  • {:ok, ips} - List of root IP addresses
  • {:error, %Error{}} - Error with details
Link to this function

historical_orders(user, opts \\ [])

View Source
@spec historical_orders(String.t(), request_opts()) :: response()

Fetch user's historical orders.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, orders} - List of historical orders
  • {:error, %Error{}} - Error with details
Link to this function

historical_orders!(user, opts \\ [])

View Source

Fetch user's historical orders. Raises on error.

Link to this function

info_request(payload, opts \\ [])

View Source
@spec info_request(map(), request_opts()) :: response()

Make a request to the Info API.

The Info API is used for read-only queries and doesn't require authentication.

Parameters

  • payload: Map with query parameters (must include "type" key)
  • opts: Optional HTTPoison options

Returns

  • {:ok, response} - Parsed JSON response (snake_cased)
  • {:error, %Error{}} - Error with details

Examples

# Get all mid prices
{:ok, mids} = Http.info_request(%{type: "allMids"})

# Get user state
{:ok, state} = Http.info_request(%{type: "clearinghouseState", user: "0x..."})

# Get meta information
{:ok, meta} = Http.info_request(%{type: "meta"})
Link to this function

is_vip(user, opts \\ [])

View Source
@spec is_vip(String.t(), request_opts()) :: response()

Check if user is a VIP.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, status} - VIP status
  • {:error, %Error{}} - Error with details
Link to this function

l2_book(coin, opts \\ [])

View Source
@spec l2_book(String.t(), request_opts()) :: response()

Fetch L2 order book snapshot.

Parameters

  • coin: Coin symbol (e.g., "BTC")
  • opts: Optional HTTPoison options

Returns

  • {:ok, book} - Order book with levels
  • {:error, %Error{}} - Error with details
Link to this function

l2_book!(coin, opts \\ [])

View Source

Fetch L2 order book snapshot. Raises on error.

@spec leaderboard(request_opts()) :: response()

Fetch leaderboard data from the stats API.

Parameters

  • opts: Optional HTTPoison options

Returns

  • {:ok, leaderboard} - Leaderboard data with trader rankings
  • {:error, %Error{}} - Error with details
Link to this function

leaderboard!(opts \\ [])

View Source

Fetch leaderboard data from the stats API. Raises on error.

@spec meta(request_opts()) :: response()

Fetch perpetuals metadata.

Returns

  • {:ok, meta} - Perpetuals metadata
  • {:error, %Error{}} - Error with details

Fetch perpetuals metadata. Raises on error.

Link to this function

meta_and_asset_ctxs(opts \\ [])

View Source
@spec meta_and_asset_ctxs(request_opts()) :: response()

Fetch perpetuals metadata with asset contexts.

Returns

  • {:ok, [meta, asset_ctxs]} - Meta and asset contexts
  • {:error, %Error{}} - Error with details
Link to this function

meta_and_asset_ctxs!(opts \\ [])

View Source

Fetch perpetuals metadata with asset contexts. Raises on error.

Link to this function

open_orders(user, opts \\ [])

View Source
@spec open_orders(String.t(), request_opts()) :: response()

Fetch user's open orders.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, orders} - List of open orders
  • {:error, %Error{}} - Error with details
Link to this function

open_orders!(user, opts \\ [])

View Source

Fetch user's open orders. Raises on error.

Link to this function

perp_deploy_auction_status(opts \\ [])

View Source
@spec perp_deploy_auction_status(request_opts()) :: response()

Fetch perpetual deploy auction status.

Returns

  • {:ok, status} - Auction status
  • {:error, %Error{}} - Error with details
Link to this function

perp_dex_limits(dex, opts \\ [])

View Source
@spec perp_dex_limits(String.t(), request_opts()) :: response()

Fetch limits for a specific perpetual DEX.

Parameters

  • dex: DEX name
  • opts: Optional HTTPoison options

Returns

  • {:ok, limits} - DEX limits
  • {:error, %Error{}} - Error with details
@spec perp_dexs(request_opts()) :: response()

Fetch all perpetual DEXs.

Returns

  • {:ok, dexs} - List of perpetual DEXs
  • {:error, %Error{}} - Error with details

Fetch all perpetual DEXs. Raises on error.

Link to this function

perps_at_open_interest_cap(opts \\ [])

View Source
@spec perps_at_open_interest_cap(request_opts()) :: response()

Fetch list of perpetuals at their open interest cap.

Returns

  • {:ok, coins} - List of coin symbols
  • {:error, %Error{}} - Error with details
Link to this function

portfolio(user, opts \\ [])

View Source
@spec portfolio(String.t(), request_opts()) :: response()

Fetch user's portfolio performance data.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, portfolio} - Portfolio data across timeframes
  • {:error, %Error{}} - Error with details
Link to this function

portfolio!(user, opts \\ [])

View Source

Fetch user's portfolio performance data. Raises on error.

Link to this function

post(url, body, opts \\ [])

View Source
@spec post(String.t(), map(), request_opts()) :: response()

Make a raw POST request to any endpoint.

Parameters

  • url: Full URL or path (will be appended to api_base if relative)
  • body: Request body (will be JSON encoded)
  • opts: Optional HTTPoison options

Returns

  • {:ok, response} - Parsed JSON response (snake_cased)
  • {:error, %Error{}} - Error with details

Examples

{:ok, data} = Http.post("/info", %{type: "allMids"})
{:ok, data} = Http.post("https://api.hyperliquid.xyz/info", %{type: "meta"})
Link to this function

pre_transfer_check(user, destination, amount, opts \\ [])

View Source
@spec pre_transfer_check(String.t(), String.t(), String.t(), request_opts()) ::
  response()

Check if a transfer can be made.

Parameters

  • user: User address (0x...)
  • destination: Destination address (0x...)
  • amount: Amount to transfer as string
  • opts: Optional HTTPoison options

Returns

  • {:ok, check} - Transfer check result
  • {:error, %Error{}} - Error with details
Link to this function

predicted_fundings(opts \\ [])

View Source
@spec predicted_fundings(request_opts()) :: response()

Fetch predicted funding rates.

Returns

  • {:ok, predictions} - Funding rate predictions
  • {:error, %Error{}} - Error with details
Link to this function

predicted_fundings!(opts \\ [])

View Source

Fetch predicted funding rates. Raises on error.

Link to this function

recent_trades(coin, opts \\ [])

View Source
@spec recent_trades(String.t(), request_opts()) :: response()

Fetch recent trades for a coin.

Parameters

  • coin: Coin symbol (e.g., "BTC")
  • opts: Optional HTTPoison options

Returns

  • {:ok, trades} - List of recent trades
  • {:error, %Error{}} - Error with details
Link to this function

recent_trades!(coin, opts \\ [])

View Source

Fetch recent trades for a coin. Raises on error.

Link to this function

referral(user, opts \\ [])

View Source
@spec referral(String.t(), request_opts()) :: response()

Fetch user's referral information.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, referral} - Referral info and rewards
  • {:error, %Error{}} - Error with details
Link to this function

referral!(user, opts \\ [])

View Source

Fetch user's referral information. Raises on error.

Link to this function

spot_clearinghouse_state(user, opts \\ [])

View Source
@spec spot_clearinghouse_state(String.t(), request_opts()) :: response()

Fetch user's spot clearinghouse state.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, state} - Spot clearinghouse state with balances
  • {:error, %Error{}} - Error with details
Link to this function

spot_clearinghouse_state!(user, opts \\ [])

View Source

Fetch user's spot clearinghouse state. Raises on error.

@spec spot_meta(request_opts()) :: response()

Fetch spot metadata.

Returns

  • {:ok, meta} - Spot metadata
  • {:error, %Error{}} - Error with details

Fetch spot metadata. Raises on error.

Link to this function

spot_meta_and_asset_ctxs(opts \\ [])

View Source
@spec spot_meta_and_asset_ctxs(request_opts()) :: response()

Fetch spot metadata with asset contexts.

Returns

  • {:ok, [meta, asset_ctxs]} - Spot meta and asset contexts
  • {:error, %Error{}} - Error with details
Link to this function

spot_meta_and_asset_ctxs!(opts \\ [])

View Source

Fetch spot metadata with asset contexts. Raises on error.

Link to this function

stats_request(endpoint, opts \\ [])

View Source
@spec stats_request(String.t(), request_opts()) :: response()

Make a request to the Stats API.

Used for leaderboard, vaults, and other stats endpoints. Stats endpoints use GET requests to a network-specific URL.

Parameters

  • endpoint: The endpoint name (e.g., "leaderboard", "vaults")
  • opts: Optional HTTPoison options

Returns

  • {:ok, response} - Parsed JSON response (snake_cased)
  • {:error, %Error{}} - Error with details

Examples

# Get leaderboard
{:ok, leaderboard} = Http.stats_request("leaderboard")

# Get vaults
{:ok, vaults} = Http.stats_request("vaults")
Link to this function

tx_details(hash, opts \\ [])

View Source
@spec tx_details(String.t(), request_opts()) :: response()

Fetch transaction details from the explorer.

Parameters

  • hash: Transaction hash (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, tx_details} - Transaction details
  • {:error, %Error{}} - Error with details
Link to this function

user_details(user, opts \\ [])

View Source
@spec user_details(String.t(), request_opts()) :: response()

Fetch user details from the explorer.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, user_details} - User details
  • {:error, %Error{}} - Error with details
Link to this function

user_fills(user, opts \\ [])

View Source
@spec user_fills(String.t(), request_opts()) :: response()

Fetch user's order history.

Parameters

  • user: User address (0x...)
  • opts: Optional HTTPoison options

Returns

  • {:ok, orders} - List of historical orders
  • {:error, %Error{}} - Error with details
Link to this function

user_fills!(user, opts \\ [])

View Source

Fetch user's order history. Raises on error.

Link to this function

user_signed_request(action, signature, nonce, opts \\ [])

View Source
@spec user_signed_request(map(), map(), non_neg_integer(), request_opts()) ::
  response()

Make a user-signed (EIP-712) exchange request.

Used for actions like usdSend, withdraw3, spotSend that use typed data signatures.

Parameters

  • action: The action payload
  • signature: Signature map with r, s, v
  • nonce: Request nonce (timestamp)
  • opts: Request options

Returns

  • {:ok, response} - Parsed response
  • {:error, %Error{}} - Error with details
@spec vaults(request_opts()) :: response()

Fetch vaults data from the stats API.

Parameters

  • opts: Optional HTTPoison options

Returns

  • {:ok, vaults} - List of vaults with performance metrics
  • {:error, %Error{}} - Error with details

Fetch vaults data from the stats API. Raises on error.