SDK guide
JavaScript
REST API + WebSocket

Hyperliquid JavaScript SDK

Build with the Hyperliquid REST API & WebSockets with our JavaScript SDK, TypeScript-first package declarations, and Node.js-compatible runtime patterns. Discover installation, common examples, a detailed endpoint-to-function map, and the REST API/WebSocket patterns shared across our Siebly SDK family.

Use the same TypeScript-first REST API and WebSocket clients from plain JavaScript or TypeScript in Node.js-compatible runtimes.

Package surfaces

Explore the following API capabilities are covered by our Hyperliquid SDK:

  • Perpetuals
  • Spot
  • Account State
  • WebSockets
  • WebSocket API
  • Testnet
  • WebSocket clients with:
    • Built-in heartbeats.
    • Automatic reconnection.
    • Automatic reauthentication and resubscribe where the exchange supports it.
  • Promise-wrapped WebSocket API commands you can await like a REST API.
  • Typed requests and responses for Node.js, JavaScript, and TypeScript IDEs.
  • Framework-neutral JavaScript snippets that stay approachable in Node.js-compatible runtimes.
  • TypeScript-first package declarations for stricter services, shared libraries, and editor-assisted integrations.

Install Hyperliquid SDK

# Via your favourite package manager, e.g. npm:
npm install @siebly/hyperliquid-api
# or pnpm:
pnpm install @siebly/hyperliquid-api
# or yarn:
yarn add @siebly/hyperliquid-api

Quickstart Examples with the Hyperliquid JavaScript SDK

Get started with just a few lines of JavaScript. TypeScript, while not required, is absolutely recommended. TypeScript declarations are included with all our SDKs and provide convenient definitions on request & response fields, WebSocket payloads, and generally safer integrations.

import { RestClient } from '@siebly/hyperliquid-api'; const client = new RestClient(); async function main() {  try {    const status = await client.getExchangeStatus();    console.log('Exchange status:', status);  } catch (error) {    console.error('Exchange-status request failed:', error);  }   try {    const mids = await client.getAllMids();    console.log('BTC midpoint:', mids.BTC);  } catch (error) {    console.error('Midpoint request failed:', error);  }   try {    const metadata = await client.getPerpMetadata();    const btc = metadata.universe.find((asset) => asset.name === 'BTC');    console.log('BTC perpetual metadata:', btc);  } catch (error) {    console.error('Perpetual metadata request failed:', error);  }   try {    const orderBook = await client.getOrderBook({      coin: 'BTC',    });    console.log('Best bid:', orderBook?.levels[0][0]);    console.log('Best ask:', orderBook?.levels[1][0]);  } catch (error) {    console.error('Order-book request failed:', error);  }   try {    const candles = await client.getCandles({      coin: 'BTC',      interval: '1h',      startTime: Date.now() - 24 * 60 * 60 * 1000,    });    console.log('Latest hourly candle:', candles.at(-1));  } catch (error) {    console.error('Candle request failed:', error);  }   try {    const trades = await client.getRecentTrades({      coin: 'BTC',    });    console.log('Most recent trade:', trades[0]);  } catch (error) {    console.error('Recent-trade request failed:', error);  }} main();
Hyperliquid REST API example: rest-public.ts source
GitHub snippet matches cached snippet.
Full Hyperliquid course

Hyperliquid API JavaScript Tutorial

A practical JavaScript guide to using @siebly/hyperliquid-api for Hyperliquid market data, account state, perpetual and Spot orders, WebSocket streams, WebSocket API requests, Testnet, proxies, and recovery.

Perpetual and Spot REST API calls
Public and account WebSocket streams
Testnet order workflows
REST API and WebSocket proxy examples
REST API
WebSocket Streams
WebSocket API
Examples

Your app / service

bot, dashboard, worker

@siebly/hyperliquid-api

RestClient, WebsocketClient, WebsocketAPIClient

Hyperliquid APIs

Info requests, signed Exchange actions, streaming subscriptions, and WebSocket POST requests

Common Hyperliquid implementation tasks

Hyperliquid JavaScript FAQ

What does the Hyperliquid JavaScript SDK cover?

Hyperliquid supports Perpetuals, Spot, Account State, WebSockets, WebSocket API, and Testnet workflows. The JavaScript guide covers the main REST and WebSocket integration patterns.

How do I authenticate private Hyperliquid API calls in JavaScript?

Install @siebly/hyperliquid-api from npm & pass API credentials into the SDK client options, as shown in the Hyperliquid JavaScript examples above. The SDK handles the exchange-specific signing requirements for private requests.

Does the Hyperliquid JavaScript SDK help with WebSocket connection management?

Yes. Use the SDK WebSocket client for subscriptions, reconnect handling, and stream lifecycle management instead of building raw socket flows yourself.

When should I use the Hyperliquid WebSocket API instead of REST?

Use REST for standard request and response workflows such as account queries and order management. Use the WebSocket API flow when you want persistent low-latency interactions over a connected session.

Direct Example Files

Open the example files below for JavaScript and TypeScript-compatible request, authentication, WebSocket, and Node.js service patterns.

Continue with implementation resources

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.