Quick Start
1
2
Create a Client
import { HttpTransport, InfoClient } from "@nktkas/hyperliquid";
const transport = new HttpTransport();
const info = new InfoClient({ transport });import { ExchangeClient, HttpTransport } from "@nktkas/hyperliquid";
import { privateKeyToAccount } from "viem/accounts";
const wallet = privateKeyToAccount("0x..."); // viem account or ethers signer
const transport = new HttpTransport();
const exchange = new ExchangeClient({ transport, wallet });import { SubscriptionClient, WebSocketTransport } from "@nktkas/hyperliquid";
const transport = new WebSocketTransport();
const subs = new SubscriptionClient({ transport });3
Use the Client
// Retrieve mids for all coins
const mids = await info.allMids();
// Retrieve a user's open orders
const openOrders = await info.openOrders({ user: "0x..." });
// L2 book snapshot
const book = await info.l2Book({ coin: "BTC" });// Place an order
const result = await exchange.order({
orders: [{
a: 0,
b: true,
p: "95000",
s: "0.01",
r: false,
t: { limit: { tif: "Gtc" } },
}],
grouping: "na",
});
// Update leverage
await exchange.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
// Initiate a withdrawal request
await exchange.withdraw3({ destination: "0x...", amount: "1" });Last updated