Clients

A client uses a transport to call a specific part of the Hyperliquid API:

  • Info: market data, account state, blockchain explorer

  • Exchange: trading, fund management, account configuration

  • Subscription: real-time updates via WebSocket

Read data

InfoClient gives read-only access to the Info endpointarrow-up-right. Works with any transport.

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

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

const mids = await client.allMids();
const book = await client.l2Book({ coin: "ETH" });

Trading

ExchangeClient executes actions on the Exchange endpointarrow-up-right: trading, fund management, and account configuration. Requires a wallet for signing and works with any transport.

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

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

Place an order:

Multi-sig

Multi-signature accountsarrow-up-right require multiple authorized signers to approve every action. The leader (first signer in the array) collects all signatures and submits the final transaction — only the leader's nonce is validated by the server.

Vault and sub-account trading

To trade on behalf of a vault or sub-accountarrow-up-right, set a default or pass vaultAddress per-request:

Expiration

A server-side guard. The API rejects the action after this timestamp (milliseconds). See Expires Afterarrow-up-right.

Signature chain ID

Sets the EIP-712 domain chainId for user-signed actions. Defaults to the wallet's provider chain ID. Local wallets without a provider (e.g., privateKeyToAccountarrow-up-right, new Wallet()arrow-up-right) fall back to 0x1 (Ethereum mainnet). Override to set the correct chain:

Nonce manager

The SDK generates noncesarrow-up-right automatically using timestamps with auto-increment. Replace it if you need custom logic:

Real-time updates

SubscriptionClient streams live data via WebSocket subscriptionsarrow-up-right. Requires WebSocketTransport.

Unsubscribe

A single connection supports up to 1000 active subscriptions and 10 unique usersarrow-up-right. Call unsubscribe() to remove a listener and free these slots:

Subscribing to the same channel multiple times reuses one underlying subscription. Each unsubscribe() removes only its listener — the channel stays open until the last one is removed:

Handle failures

When the WebSocket reconnects, the SDK automatically resubscribes to all active channels. If resubscription fails for a channel, its failureSignal aborts with the error:

Common options

Cancellation

InfoClient methods accept an optional AbortSignalarrow-up-right as the last argument:

ExchangeClient methods accept it inside the options object (also last argument). Unlike Expiration, which is a server-side guard, cancellation aborts the request on the client side before or during delivery:

Last updated