Clients

Clients provide methods to interact with the Hyperliquid API. Each client corresponds to a specific API type.

InfoClient

Read-only access to market data, user state, and other public information. Corresponds to the Info endpointarrow-up-right.

Import

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

Usage

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

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

// Get all mid prices
const mids = await client.allMids();

// Get user's perpetual positions
const state = await client.clearinghouseState({
  user: "0x...",
});

Parameters

transport (required)

The transport used to send requests.

ExchangeClient

Execute actions: place orders, cancel orders, transfer funds, etc. Corresponds to the Exchange endpointarrow-up-right.

Requires a wallet for signing. The SDK handles signingarrow-up-right and noncesarrow-up-right automatically.

Import

Usage with viem

Usage with ethers

Usage with Multi-Sig

Parameters

transport (required)

The transport used to send requests.

wallet (required for single wallet)

  • Type: AbstractWallet

The wallet used to sign requests. Supports:

signers (required for multi-sig)

  • Type: [AbstractWallet, ...AbstractWallet[]]

Array of wallets for multi-sig signing. The first wallet is the leaderarrow-up-right.

multiSigUser (required for multi-sig)

  • Type: `0x${string}`

The multi-signature account address.

signatureChainId (optional)

  • Type: `0x${string}` | (() => MaybePromise<0x${string}>)

  • Default: Wallet's connected chain ID

Custom chain ID for EIP-712 signing.

defaultVaultAddress (optional)

  • Type: `0x${string}`

Default vault address for vault-based operations. Can be overridden per-request.

defaultExpiresAfter (optional)

  • Type: number | (() => MaybePromise<number>)

Default expiration time in milliseconds for actions. See Expires Afterarrow-up-right.

nonceManager (optional)

  • Type: (address: string) => MaybePromise<number>

  • Default: Timestamp-based with auto-increment

Custom nonce generator. See Hyperliquid noncesarrow-up-right.

SubscriptionClient

Real-time data via WebSocket subscriptions. Corresponds to WebSocket subscriptionsarrow-up-right.

Requires WebSocketTransport.

Import

Usage

Subscription Object

Each subscription returns an object with:

  • unsubscribe() - Stop receiving updates

  • failureSignal - AbortSignalarrow-up-right that aborts if resubscription fails after reconnect

Parameters

transport (required)

Must be WebSocketTransport. Does not work with HttpTransport.

Last updated