Read Hyperliquid Market Metadata and Mid Prices

Use Hyperliquid’s public info API to retrieve asset metadata and current market contexts, with response validation and practical error handling.

To inspect Hyperliquid markets, send a POST request to its public info API with the metaAndAssetCtxs request type. This returns asset metadata alongside market contexts, including mid prices when available. The guide uses Node.js 18+ and checks the response before reading it.

Request metadata and market contexts

Hyperliquid’s info API accepts JSON POST requests. The metaAndAssetCtxs request returns two arrays: universe metadata and corresponding asset contexts. This example reads them from the public API; it does not require an indexing service.

  • Use the asset’s position in the metadata universe to match it with the context at the same position.
  • Market values change, so treat the output as a snapshot from the time of the request.
JavaScript · Node.js
const endpoint = 'https://api.hyperliquid.xyz/info';

async function main() {
  const response = await fetch(endpoint, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ type: 'metaAndAssetCtxs' }),
    signal: AbortSignal.timeout(15_000),
  });

  if (!response.ok) {
    throw new Error(`Hyperliquid API returned HTTP ${response.status}`);
  }

  const data = await response.json();
  if (!Array.isArray(data) || data.length < 2 ||
      !Array.isArray(data[0]?.universe) || !Array.isArray(data[1])) {
    throw new Error('Unexpected response: expected metadata and asset contexts');
  }

  const assets = data[0].universe;
  const contexts = data[1];
  if (assets.length !== contexts.length) {
    throw new Error(`Asset/context count mismatch: ${assets.length} vs ${contexts.length}`);
  }

  const markets = assets.map((asset, index) => ({
    name: asset.name,
    midPrice: contexts[index]?.midPx ?? null,
  }));
  console.log(JSON.stringify(markets, null, 2));
}

main().catch((error) => {
  console.error(`Could not read Hyperliquid market data: ${error.message}`);
  process.exitCode = 1;
});

Run with node market.js on Node.js 18 or later. The expected result is a JSON array of asset names and their returned mid prices; the actual entries and values depend on the response at request time.

A timeout, network failure, non-success HTTP status, or unexpected response shape produces an error message and a nonzero process exit code.

Use the snapshot carefully

The midPx field is supplied by the API as a value that may be absent, which the example represents as null. Keep prices as strings when passing them to other code if exact decimal handling matters; converting them to JavaScript numbers can introduce rounding.

This request gives you current API data, not a historical record. If you need to analyze past market states, store snapshots with timestamps or use an indexing workflow that exposes the historical data you require.

  • Record when each snapshot was fetched if you persist results.
  • Check the API’s current documentation for request and response details before relying on fields in production.

Choose RPC access or indexing

This example uses an HTTP API to request a market snapshot. RPC access is for sending requests to a network service; indexing collects and organizes data so applications can query it, often for historical or application-specific views. A market-data API request by itself does not create an index or provide historical queries.

For Hyperliquid network access options, see the Hyperliquid network page. If your next task is building a data workflow, continue with OnFinality Learn.