Market data
Use RestClient for public HTTP requests. These examples do not need account credentials.
Mid prices
import { RestClient } from '@siebly/hyperliquid-api';
async function main() {
const client = new RestClient();
const mids = await client.getAllMids();
if (mids.BTC === undefined) {
throw new Error('BTC was not present in the mid-price response.');
}
console.log('BTC mid price:', mids.BTC);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});An empty book falls back to the last trade price. Spot mids are included when dex is omitted or empty. Use the optional dex parameter to query a specific perpetual DEX.
L2 order book
import { RestClient } from '@siebly/hyperliquid-api';
async function main() {
const client = new RestClient();
const book = await client.getOrderBook({ coin: 'BTC' });
if (!book) {
console.log('No order book was returned for BTC.');
return;
}
const [bids, asks] = book.levels;
console.log({ bestBid: bids[0] ?? null, bestAsk: asks[0] ?? null });
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});The response can be null, so check it before reading levels. The two arrays contain bids and asks, with up to 20 levels per side. Optional nSigFigs and mantissa parameters control aggregation.
The example prints the best bid and ask, or null for an empty side. A level contains px (price), sz (size) and n (number of orders). Prices and sizes are decimal strings. Illustrative output:
{
"bestBid": { "px": "65000", "sz": "0.42", "n": 3 },
"bestAsk": { "px": "65001", "sz": "0.15", "n": 2 }
}getOrderBook reference · Request parameters · Response fields
Candle history
import { RestClient } from '@siebly/hyperliquid-api';
async function main() {
const client = new RestClient();
const candles = await client.getCandles({
coin: 'BTC',
interval: '1h',
startTime: Date.now() - 24 * 60 * 60 * 1000,
});
console.log(candles);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});This example requests hourly BTC candles starting 24 hours ago. Times are Unix milliseconds. Only the most recent 5,000 candles are available.
getCandles reference · Request parameters · Candle response
Asset names
Use BTC for a native perpetual, @107 for a native Spot identifier, or a dex:COIN name for a HIP-3 market. getOrderBook, getCandles and getFundingHistory can resolve readable Spot aliases through metadata. Other Info methods and stream subscriptions pass coin through unchanged.