Tree-shaking

The SDK supports tree-shaking through granular imports - reduce bundle size by ~50% by importing only the functions you need.

Import

// Granular imports (tree-shakeable)
import { clearinghouseState } from "@nktkas/hyperliquid/api/info";
import { order } from "@nktkas/hyperliquid/api/exchange";
import { candle } from "@nktkas/hyperliquid/api/subscription";

Usage

Functions have the same names as client methods. Instead of client.order(...), you call order(config, ...):

import { HttpTransport } from "@nktkas/hyperliquid";
import { order } from "@nktkas/hyperliquid/api/exchange";
import { privateKeyToAccount } from "viem/accounts";

const transport = new HttpTransport();
const wallet = privateKeyToAccount("0x...");

// Function takes config as first argument
const result = await order(
  { transport, wallet },
  {
    orders: [{
      a: 0,
      b: true,
      p: "30000",
      s: "0.1",
      r: false,
      t: { limit: { tif: "Gtc" } },
    }],
    grouping: "na",
  },
);

Compare with client approach:

Info Functions

Info functions only need transport:

Exchange Functions

Exchange functions require transport and wallet:

Subscription Functions

Subscription functions require WebSocketTransport:

Available Exports

Export Path
Description

@nktkas/hyperliquid/api/info

Info API functions (clearinghouseState, meta, allMids, etc.)

@nktkas/hyperliquid/api/exchange

Exchange API functions (order, cancel, withdraw3, etc.)

@nktkas/hyperliquid/api/subscription

Subscription functions (candle, trades, l2Book, etc.)

Valibot Schemas

These exports also include valibotarrow-up-right schemas for every API method:

Available Schemas

Each method exports:

  • *Request - full request schema (with type, nonce, signature for exchange)

  • *Response - response schema from API

Use Cases

TypeScript types:

Runtime validation:

Field descriptions:

Schemas include descriptions for all fields via v.description(), useful for generating documentation or exploring the API structure.

Last updated