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 requestsConfig.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 block details.
Fetch candle data.
Fetch candle data. Raises on error.
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.
Make a request to the Exchange API.
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.
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.
Check if a transfer can be made.
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() ]
Functions
@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
@spec aligned_quote_token_info(non_neg_integer(), request_opts()) :: response()
Fetch aligned quote token info.
Parameters
token: Token indexopts: 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.
@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
@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
@spec candles( String.t(), String.t(), non_neg_integer(), non_neg_integer(), request_opts() ) :: response()
Fetch candle data.
Parameters
coin: Coin symbolinterval: Candle interval (e.g., "1m", "1h", "1d")start_time: Start timestamp in msend_time: End timestamp in msopts: Optional HTTPoison options
Returns
{:ok, candles}- List of candle data{:error, %Error{}}- Error with details
Fetch candle data. Raises on error.
@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
Fetch user's perpetuals clearinghouse state. Raises on error.
@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
@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
@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
@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
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 signaturenonce: Timestamp noncevault_address: Optional vault addressopts: 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
)
@spec exchange_status(request_opts()) :: response()
Fetch exchange status.
Returns
{:ok, status}- Exchange operational status{:error, %Error{}}- Error with details
Fetch exchange status. Raises on error.
@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 parametersopts: 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..."})
@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
Fetch user's extra agents. Raises on error.
@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
Fetch user's open orders with frontend info. Raises on error.
@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 msend_time: Optional end timestamp in msopts: Optional HTTPoison options
Returns
{:ok, funding}- Funding history{:error, %Error{}}- Error with details
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
@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
@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
Fetch user's historical orders. Raises on error.
@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"})
@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
@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
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
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.
@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
Fetch perpetuals metadata with asset contexts. Raises on error.
@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
Fetch user's open orders. Raises on error.
@spec perp_deploy_auction_status(request_opts()) :: response()
Fetch perpetual deploy auction status.
Returns
{:ok, status}- Auction status{:error, %Error{}}- Error with details
@spec perp_dex_limits(String.t(), request_opts()) :: response()
Fetch limits for a specific perpetual DEX.
Parameters
dex: DEX nameopts: 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.
@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
@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
Fetch user's portfolio performance data. Raises on error.
@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"})
@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 stringopts: Optional HTTPoison options
Returns
{:ok, check}- Transfer check result{:error, %Error{}}- Error with details
@spec predicted_fundings(request_opts()) :: response()
Fetch predicted funding rates.
Returns
{:ok, predictions}- Funding rate predictions{:error, %Error{}}- Error with details
Fetch predicted funding rates. Raises on error.
@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
Fetch recent trades for a coin. Raises on error.
@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
Fetch user's referral information. Raises on error.
@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
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.
@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
Fetch spot metadata with asset contexts. Raises on error.
@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")
@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
@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
@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
Fetch user's order history. Raises on error.
@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 payloadsignature: Signature map with r, s, vnonce: 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.