Quick Start
Get started with the SDK in just a few lines of code.
1
Set up Transport
First, create a Transport — the layer that handles communication with Hyperliquid servers.
Use HttpTransport for simple requests.
import { HttpTransport } from "@nktkas/hyperliquid";
const transport = new HttpTransport();Use WebSocketTransport for subscriptions or lower latency.
import { WebSocketTransport } from "@nktkas/hyperliquid";
const transport = new WebSocketTransport();2
Create a Client
Next, create a Client with your transport. The SDK provides three clients for different purposes:
Use InfoClient to query market data, account state, and other read-only information.
import { HttpTransport, InfoClient } from "@nktkas/hyperliquid";
const transport = new HttpTransport();
const client = new InfoClient({ transport });
// Get mid prices for all assets
const mids = await client.allMids();
// => { "BTC": "97000.5", "ETH": "3500.25", ... }Use ExchangeClient to place orders, transfer funds, and perform other actions that require signing.
import { ExchangeClient, HttpTransport } from "@nktkas/hyperliquid";
import { privateKeyToAccount } from "viem/accounts";
const transport = new HttpTransport();
const client = new ExchangeClient({
transport,
wallet: privateKeyToAccount("0x..."), // viem account or ethers signer
});
// Place a limit order
const result = await client.order({
orders: [{
a: 0, // Asset index (0 = BTC)
b: true, // Buy side
p: "95000", // Price
s: "0.01", // Size
r: false, // Not reduce-only
t: { limit: { tif: "Gtc" } },
}],
grouping: "na",
});
// => { status: "ok", response: { type: "order", data: { statuses: [...] } } }Use SubscriptionClient to subscribe to live market data via WebSocket.
import { SubscriptionClient, WebSocketTransport } from "@nktkas/hyperliquid";
const transport = new WebSocketTransport();
const client = new SubscriptionClient({ transport });
// Subscribe to all mid prices
const subscription = await client.allMids((data) => {
console.log("Price update:", data.mids);
});
// Later: unsubscribe
await subscription.unsubscribe();Last updated