Blog · Published November 29, 2026 · Updated November 29, 2026 · 9 min read
How to Use the Hyperliquid API from Node.js and TypeScript
Edited by OSSDrop for structure, accuracy and search. The writer used AI tools; every claim was checked against its source before publishing.
On this page · 10 sections
To call the Hyperliquid API from Node.js or TypeScript, install an SDK from npm, create a client and call typed methods instead of building raw POST bodies and signatures yourself. This guide uses @siebly/hyperliquid-api, an MIT-licensed SDK with three clients: RestClient for market data, account state and signed actions over HTTP; WebsocketClient for live subscriptions with automatic reconnect and resubscribe; and WebsocketAPIClient for the same request methods sent over Hyperliquid's WebSocket protocol.
Public market data needs no key or account. Signed actions need a private key or an external signer, and you should try them on testnet first.
Disclosure: I help maintain this SDK, so treat the praise with the usual care and read the limitations section, which I have tried to make the most useful part of the page. Every command and output below was run on 28 November 2026 with Node.js 24.22.1 and version 1.0.5 of the package. The 'How we checked' section says what OSSDrop verified independently.
How we checked
This guide was written by a maintainer of the SDK it covers and submitted to OSSDrop; we edited it for structure and accuracy. On 29 November 2026 we checked the following at the source:
- The package: version 1.0.5 is the latest on npm, the licence is MIT, version 1.0.0 was published on 27 October 2026, and the README states Node.js 22 or newer.
- The code: we downloaded the published package and confirmed that every method and option used in the examples exists in its type definitions (
getAllMids,getOrderBook,getCandles,resolveAsset,submitLimitOrder,submitMarketOrder,submitMarketClose,postOnly,accountAddress,nSigFigs,connectionTimeout), that the default WebSocket connect timeout is 1,000 ms, and that the asset-metadata cache lasts five minutes. - The alternatives: licence, star count and last activity for each, read from its GitHub repository, and what Hyperliquid's own API documentation links.
We did not re-run the trading examples. The printed outputs are a snapshot from the writer's run: market prices and trade counts change every second. This is not financial advice, and OSSDrop has no commercial relationship with Siebly or Hyperliquid.
How the Hyperliquid API works
Hyperliquid exposes two HTTP endpoints, /info for reads and /exchange for signed actions, plus a WebSocket at wss://api.hyperliquid.xyz/ws that carries both subscriptions and request and response pairs. The raw API asks you to handle several details by hand:
- numeric asset IDs that follow different offset rules for perpetuals, spot pairs and HIP-3 markets;
- decimal strings for every price and size;
- MessagePack hashing and EIP-712 signatures for trading actions;
- nonces that must keep rising;
- a WebSocket that the server closes if it goes quiet.
The SDK wraps those pieces. Readable names such as BTC, HYPE/USDC or @107 are resolved to asset IDs from live metadata, which is cached for five minutes. Prices and sizes stay as exact strings, so floating point never touches an order. Signing, nonces and the ping and pong cycle on the socket are handled inside the clients. The package ships ESM and CommonJS builds with full type declarations, so the same code works in plain JavaScript and in TypeScript.
Install and set up
You need Node.js 22 or newer.
mkdir hl-demo && cd hl-demo
npm init -y
npm install @siebly/hyperliquid-apiThe examples below are ES modules, so save them with the .mjs extension. The README also has quickstart guides for Bun, Deno, Next.js route handlers, React with Vite, React Native with Expo and Cloudflare Workers.
Step 1: read public market data
Save this as rest.mjs. No key is needed.
import { RestClient } from '@siebly/hyperliquid-api';
const client = new RestClient();
const mids = await client.getAllMids();
console.log('BTC mid:', mids.BTC);
const book = await client.getOrderBook({ coin: 'BTC', nSigFigs: 5 });
console.log('Best bid:', book.levels[0][0].px, 'Best ask:', book.levels[1][0].px);
const candles = await client.getCandles({
coin: 'ETH',
interval: '1h',
startTime: Date.now() - 24 * 60 * 60 * 1000,
});
console.log('ETH 1h candles in the last day:', candles.length);
console.log('Last close:', candles.at(-1).c);
const asset = await client.resolveAsset('HYPE/USDC');
console.log('HYPE/USDC spot asset id:', asset.assetId, asset.canonicalName);Running node rest.mjs on 28 November 2026 printed the following (prices move constantly, so yours will differ):
BTC mid: 59789.5
Best bid: 59800.0 Best ask: 59801.0
ETH 1h candles in the last day: 25
Last close: 1657.9
HYPE/USDC spot asset id: 10107 @107The last line shows why the asset helper matters: the spot pair you see as HYPE/USDC is @107 on the wire, and its trading asset ID is 10107, not 107. Sending 107 would target a different market.
Step 2: stream live trades over WebSocket
Save this as ws.mjs:
import { WebsocketClient } from '@siebly/hyperliquid-api';
// A longer connect timeout helps on slow or distant networks.
const ws = new WebsocketClient({ connectionTimeout: 10_000 });
let count = 0;
ws.on('message', (event) => {
if (event.channel === 'trades') {
for (const t of event.data) console.log(t.coin, t.side, t.px, t.sz);
count += event.data.length;
}
});
ws.on('exception', (e) => console.error('WS error', e));
const topic = { type: 'trades', coin: 'BTC' };
await ws.subscribe(topic);
setTimeout(async () => {
await ws.unsubscribe(topic);
ws.closeAll();
console.log('trades received in 15 s:', count);
}, 15_000);In the writer's run it logged 41 BTC trades in 15 seconds, each line looking like BTC B 59834.0 0.01972 (side B is a buy, A is a sell). If the connection drops, the client reconnects with a growing delay and sends your subscriptions again, and it emits a reconnected event so you can refetch any state you might have missed during the gap.
Step 3: place a signed order on testnet
Signed calls take a private key on a trusted backend, or an external signer with a signTypedData function, for example a viem wallet client. Start on testnet, with a key that holds no real funds:
import { RestClient } from '@siebly/hyperliquid-api';
const client = new RestClient({
privateKey: process.env.HYPERLIQUID_PRIVATE_KEY,
testnet: true,
});
const res = await client.submitLimitOrder({
symbol: 'BTC',
side: 'buy',
size: '0.001',
price: '20000',
postOnly: true,
});
console.log(JSON.stringify(res));With a freshly generated key that has never been funded, testnet rejects the call with User or API Wallet 0x... does not exist, which at least proves the request was signed and reached the exchange. Fund the testnet account first, then the same call returns an order ID. If you trade through an API wallet, pass the main account address as accountAddress so account lookups resolve to the right place.
Two safety rules: keep private keys in environment variables or a secrets manager, never in source code or a front end; and treat this guide as API documentation, not trading advice. Trading derivatives can lose money.
Which Hyperliquid SDK should you use?
Hyperliquid's API documentation links two community TypeScript SDKs (nktkas/hyperliquid and nomeida/hyperliquid) and a Python SDK; the Siebly SDK is not one of the listed ones. All four are open source on GitHub, but not all carry a licence file. Star counts and licences below were read from each repository on 29 November 2026.
If you already use one of the others and it works for you, there is little reason to switch. The choice usually comes down to which API style you find easier to read.
| SDK | Language | Licence | GitHub stars | Better at |
|---|---|---|---|---|
| @siebly/hyperliquid-api | TypeScript and JavaScript | MIT | 5 | Readable asset names with the spot, HIP-3 and outcome ID rules handled, order helpers such as submitMarketOrder and submitMarketClose, an awaitable WebSocket request client, setup guides per runtime |
| nktkas/hyperliquid | TypeScript and JavaScript | MIT | 456 | The most stars of the JavaScript SDKs, a JSR package for Deno, a few small dependencies, works with viem and ethers wallets |
| nomeida/hyperliquid | TypeScript and JavaScript | No licence file | 280 | One client object with everything on it, a ready-made browser bundle for a script tag, rate limiting |
Limitations: when not to use it
- It is young. Version 1.0.0 shipped on 27 October 2026, and the repository has 5 GitHub stars at the time of writing. Older SDKs have more answered questions and more example code from other users.
- Node.js 22 or newer. Older runtimes are not supported.
- The default WebSocket connect timeout is short. It is 1,000 ms. On slow or distant links connections can time out before they open, so set
connectionTimeouthigher, as in the example above. - Installed from npm. The README documents installation from npm only; Deno users go through the
npm:specifier. - Signing in the browser needs your own signer. Public REST calls and public subscriptions work in the browser, but never ship a private key to a front end. Use an external wallet signer there, or keep trading on a backend.
- The exchange can change its API. Response types follow the live API, so a field can change when Hyperliquid changes it. Pin your version and read the release notes before upgrading.
Verdict
If you are building a Node.js or TypeScript bot, dashboard or data pipeline for Hyperliquid and you want readable names, exact-string prices and a WebSocket client that handles reconnects for you, @siebly/hyperliquid-api is worth a look: start with the public data in step 1, then the testnet order. If you need the biggest community, a JSR package, or Python, one of the alternatives above fits better.
Browse more developer tools on OSSDrop, see the Siebly team's Bitget JavaScript SDK, or drop your own open-source tool. If a figure here has changed since 29 November 2026, tell us.
Frequently asked questions
Does the Hyperliquid API need an API key for market data?
No. Prices, order books, candles, funding and metadata are public. You only need a key or signer for orders, transfers and other actions.
How do I call the Hyperliquid API from Node.js?
Install an SDK from npm, such as @siebly/hyperliquid-api, create a RestClient, and call methods like getAllMids or getOrderBook. For live data, use WebsocketClient and subscribe to a topic such as trades. Node.js 22 or newer is required.
Can I use it with Bun, Deno or Cloudflare Workers?
Yes. The project documents setups for Bun, Deno (through the npm: specifier), Next.js route handlers, Cloudflare Workers, React with Vite and React Native with Expo.
How do I use an API wallet instead of my main key?
Create the API wallet in the Hyperliquid app, pass its private key as privateKey, and pass your main account address as accountAddress.
What happens to my WebSocket subscriptions after a disconnect?
The client reconnects and subscribes again for you, then emits a reconnected event. Requests that were in flight over the WebSocket request client are rejected rather than replayed, so retry them yourself if they matter.
Is this an official Hyperliquid SDK?
No. It is an independent open-source project. Hyperliquid's API documentation links a Python SDK and two community TypeScript SDKs; the Siebly SDK is not among them.
Is it safe to test trading code on Hyperliquid?
Use testnet first, with a key that holds no real funds, and keep private keys out of source code and front ends. This guide covers the API only and is not financial advice.
Written by
0 followers

