Logo
New RPC users get 35% off their first monthView the offer
OnFinality Learn
Network & Protocol Guides12 min read

Hyperliquid Market Structure: A Technical Guide to Perpetual and Spot Markets

Understand how Hyperliquid's perpetual and spot markets work under the hood, from order books and funding to programmatic access via RPC.

TL;DR

Hyperliquid is a Layer-1 blockchain with an on-chain order book that hosts perpetual and spot markets, all settled by the HyperBFT consensus engine. This guide explains the market primitives (order books, funding, margin, and the unified account), then walks through a reproducible procedure for querying market state programmatically via RPC. You will learn how to verify connectivity, fetch market metadata, and interpret order book and funding data, with troubleshooting steps for common failure modes. The goal is a working mental model of the Hyperliquid market and a runnable diagnostic workflow you can adapt to your own tooling.

Scope and Direct Answer

A Hyperliquid market is an order-book-based trading venue hosted directly on the Hyperliquid Layer-1 blockchain. The network exposes two flagship market types: perpetual futures (perps) and spot markets, both matching orders on-chain through the HyperCore application layer. Unlike automated market maker (AMM) DEXs, Hyperliquid uses a central limit order book (CLOB) where bids and asks are matched by price-time priority, and settlement is finalized by the HyperBFT consensus mechanism.

This article covers the technical structure of those markets, how to read their state programmatically, and how to diagnose connectivity or data issues when building against them. It assumes you are comfortable with JSON-RPC, basic trading concepts (bid, ask, funding rate, margin), and running command-line tools. It does not recommend a specific RPC provider; for endpoint selection, see the RPC Assistant guidance linked throughout.

  • Hyperliquid markets are on-chain order books, not AMM pools.
  • Perpetual markets use funding rates to anchor the mark price to an oracle price.
  • Spot markets settle actual asset transfers between accounts.
  • All market state is queryable via the Hyperliquid JSON-RPC interface.

Prerequisites and Assumptions

Before running the procedures below, ensure you have: a working HTTP client (curl, Python requests, or Node.js fetch), an RPC endpoint URL for Hyperliquid (replace the placeholder RPC_URL), and basic familiarity with JSON-RPC 2.0 request/response envelopes. You do not need a funded account to read public market data; write operations (placing orders) require a private key and are out of scope here.

The examples use the standard JSON-RPC POST pattern. Hyperliquid's API surface includes both an info endpoint (read-only queries) and an exchange endpoint (signed actions). This guide focuses on the info endpoint because it is the safest way to inspect market state without risking funds. If you need a managed endpoint, review the Hyperliquid RPC provider comparison in RPC Assistant before proceeding.

How the Hyperliquid Market Mechanism Works

Hyperliquid's architecture separates execution (HyperCore) from general-purpose programmability (HyperEVM), but both share a unified state. The market layer maintains an order book per asset. Each order book tracks resting bids and asks, and the matching engine executes crossing orders immediately. For perpetual markets, a funding mechanism periodically transfers value between longs and shorts to keep the perpetual contract price close to the underlying oracle price. The oracle price is derived from external spot markets, and the mark price is a weighted combination used for margin and liquidation calculations.

Margin is managed through a unified account model. A single account can hold collateral (USDC) and positions across multiple markets, with cross-margin or isolated-margin modes. The maintenance margin requirement determines the liquidation price. When the account equity falls below maintenance margin, the position is subject to liquidation. Understanding this model is essential for interpreting the account and position data returned by the API.

  • Order book: price-time priority matching on-chain.
  • Funding: periodic payments between longs and shorts in perpetual markets.
  • Oracle price: external reference price used for mark price and liquidations.
  • Unified account: shared collateral across markets with configurable margin mode.

Querying Market Metadata with curl

The first step in any market integration is discovering which markets exist and their parameters. The Hyperliquid info endpoint supports a meta request that returns the list of perpetual markets, their asset indices, and size decimals. The following curl command sends a JSON-RPC request to your endpoint. Replace RPC_URL with your actual endpoint.

The response contains a universe array. Each element has a name (e.g., BTC, ETH), szDecimals (the number of decimal places allowed for order sizes), and maxLeverage. Use this metadata to validate order sizes and leverage before submitting any trade. If the request fails, check that your endpoint supports the Hyperliquid JSON-RPC method namespace and that you are sending a POST with Content-Type: application/json.

curl -X POST RPC_URL \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "info",
    "params": {"type": "meta"},
    "id": 1
  }'

Fetching Order Book and Funding Data in Python

Once you know the market name, you can fetch the live order book and funding history. The l2Book request returns aggregated bid and ask levels. The fundingHistory request returns historical funding rates. The Python script below demonstrates both calls and prints a summary. It uses only the standard library and assumes RPC_URL is set as an environment variable.

The script prints the best bid, best ask, spread, and the most recent funding rate. This is a reproducible measurement procedure: run it at different times and record the outputs in a table to observe spread and funding variability. Do not hardcode expected values; market conditions change continuously. The purpose is to verify that your endpoint returns well-formed data and that you can parse it correctly.

import os, json, urllib.request

RPC_URL = os.environ["RPC_URL"]

def rpc(method, params):
    payload = json.dumps({"jsonrpc":"2.0","method":method,"params":params,"id":1}).encode()
    req = urllib.request.Request(RPC_URL, data=payload, headers={"Content-Type":"application/json"})
    with urllib.request.urlopen(req, timeout=10) as resp:
        return json.loads(resp.read())

book = rpc("info", {"type": "l2Book", "coin": "BTC"})
bids = book["result"]["levels"][0]
asks = book["result"]["levels"][1]
best_bid = float(bids[0]["px"])
best_ask = float(asks[0]["px"])
print(f"Best bid: {best_bid}, Best ask: {best_ask}, Spread: {best_ask - best_bid:.2f}")

funding = rpc("info", {"type": "fundingHistory", "coin": "BTC", "startTime": 0})
latest = funding["result"][-1]
print(f"Latest funding rate: {latest['fundingRate']} at {latest['time']}")

Expected Verification Results

After running the curl and Python examples, you should observe: a JSON response with a result object containing a universe array (for meta), an l2Book result with two arrays of price levels (bids and asks), and a fundingHistory result with an array of funding records. If any of these are missing or malformed, the endpoint or request is misconfigured.

To validate consistency, run the order book query twice within a few seconds and compare the best bid and ask. They may change, but the structure should remain stable. Record your observations in a table like the one below. Do not invent numbers; fill in the table with your own measured values.

  • | Measurement | Run 1 | Run 2 | Notes |
  • | Best bid | (your value) | (your value) | From l2Book |
  • | Best ask | (your value) | (your value) | From l2Book |
  • | Spread | (your value) | (your value) | ask - bid |
  • | Funding rate | (your value) | (your value) | From fundingHistory |

Troubleshooting Common RPC and Data Issues

If you receive a 401 or 403, your endpoint requires authentication; check your provider's documentation. A 429 indicates rate limiting; reduce request frequency or use a dedicated endpoint. A JSON-RPC error with code -32601 means the method is not supported; verify you are using the correct method name (info for read queries). A timeout suggests network latency or an overloaded endpoint; test with a simple meta request first.

If the order book returns empty arrays, the market may be illiquid or the coin name may be incorrect. Coin names are case-sensitive and must match the name field from the meta response. If funding history is empty, the startTime may be too recent; set it to 0 to fetch all available history. Always log the raw response for debugging.

  • 401/403: authentication required.
  • 429: rate limited; back off or upgrade.
  • -32601: method not found; check method name.
  • Empty order book: verify coin name and market activity.
  • Empty funding history: set startTime to 0.

Limitations and Tradeoffs

On-chain order books provide transparency and non-custodial settlement, but they also inherit blockchain constraints. Throughput is high (HyperBFT is designed for low latency), yet public RPC endpoints may rate-limit or add latency. For latency-sensitive strategies, a dedicated node or a premium RPC provider is advisable; see the Hyperliquid RPC provider comparison for options. Additionally, the unified account model means a liquidation in one market can affect collateral available to others, so risk management must account for cross-market exposure.

Another tradeoff is data freshness: the l2Book snapshot is point-in-time. For real-time updates, you would need a WebSocket subscription, which is outside the scope of this guide. Finally, the funding rate is not a prediction; it reflects past and current market conditions and can change rapidly.

Next Steps for Building on Hyperliquid

With a working read-only integration, you can proceed to build monitoring dashboards, backtesting pipelines, or alerting systems. For write operations, you will need to sign transactions with a private key and submit them to the exchange endpoint; review the official Hyperliquid documentation for signing details. To improve reliability, consider using a dedicated Hyperliquid node or a managed RPC service. For endpoint selection, consult the RPC Assistant guide on the best Hyperliquid RPC provider.

If you are deploying to production, test your integration against multiple endpoints and implement retry logic with exponential backoff. Monitor error rates and latency. For a broader overview of RPC concepts, see the RPC endpoints guide. For network-specific details, visit the Hyperliquid network page.

  • Read the Hyperliquid RPC provider comparison for endpoint options.
  • Explore dedicated node hosting for low-latency requirements.
  • Review RPC pricing if you need higher rate limits.
  • Check the networks directory for other chains.

Never Worry about Infrastructure Again

OnFinality takes away the heavy lifting of DevOps so you can build smarter and faster.

Get Started