Introduction

A TypeScript SDK for the Hyperliquid API.

npm i @nktkas/hyperliquid

Type Safe

100% TypeScript. Full inference for 80+ methods.

Tested

Types validated against real API responses.

Minimal

Few dependencies. Tree-shakeable.

Universal

Node.js, Deno, Bun, browsers, React Native.

Transports

Native fetch and WebSocket.

Wallet Support

Works with viem and ethers.

Open Source

MIT licensed on GitHub.


Examples

Read Data

import { HttpTransport, InfoClient } from "@nktkas/hyperliquid";

const client = new InfoClient({ transport: new HttpTransport() });

// Order book
const book = await client.l2Book({ coin: "ETH" });
//    ^? { coin: string, time: number, levels: [{ px: string, sz: string, n: number }[], ...] }

// Account state
const state = await client.clearinghouseState({ user: "0x..." });
//    ^? { marginSummary: {...}, assetPositions: [...], withdrawable: string }

Every method has fully typed parameters and responses. No more guessing what the API returns.

Place Orders

import { ExchangeClient, HttpTransport } from "@nktkas/hyperliquid";
import { privateKeyToAccount } from "viem/accounts";

const client = new ExchangeClient({
  transport: new HttpTransport(),
  wallet: privateKeyToAccount("0x..."),
});

const result = await client.order({
  orders: [{
    a: 4, // Asset index (ETH)
    b: true, // Buy side
    p: "3000", // Price
    s: "0.1", // Size
    r: false, // Reduce only
    t: { limit: { tif: "Gtc" } },
  }],
  grouping: "na",
});
// ^? { status: "ok", response: { type: "order", data: { statuses: [...] } } }

Real-time Updates

import { SubscriptionClient, WebSocketTransport } from "@nktkas/hyperliquid";

const client = new SubscriptionClient({ transport: new WebSocketTransport() });

await client.l2Book({ coin: "ETH" }, (book) => {
  console.log(book.coin, book.levels[0][0].px);
  //          ^? { coin: string, time: number, levels: [...] }
});

Last updated