FAQ
How to create a market order?
import { ExchangeClient, HttpTransport, InfoClient } from "@nktkas/hyperliquid";
import { privateKeyToAccount } from "viem/accounts";
const info = new InfoClient({ transport: new HttpTransport() });
const exchange = new ExchangeClient({
transport: new HttpTransport(),
wallet: privateKeyToAccount("0x..."),
});
// Get current price
const mids = await info.allMids();
const currentPrice = parseFloat(mids["ETH"]);
// Buy: set price above current (e.g., +1%)
const buyPrice = currentPrice * 1.01;
// Sell: set price below current (e.g., -1%)
const sellPrice = currentPrice * 0.99;
await exchange.order({
orders: [{
a: 4,
b: true,
p: buyPrice,
s: "0.1",
r: false,
t: { limit: { tif: "Ioc" } }, // Immediate or Cancel
}],
grouping: "na",
});How to use Agent Wallet?
How to trade on behalf of a Vault or Sub-Account?
How to sign with MetaMask or other browser wallets?
Last updated