Introduction
A TypeScript SDK for the Hyperliquid API.
npm i @nktkas/hyperliquidpnpm add @nktkas/hyperliquidyarn add @nktkas/hyperliquidbun add @nktkas/hyperliquiddeno add jsr:@nktkas/hyperliquidType 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.
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 }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