@nktkas/hyperliquid@0.6.0Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
nktkas/hyperliquidA low-level SDK for interacting with Hyperliquid's APIs in TypeScript.
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
JSR Score
100%
Published
6 days ago (0.6.0)
@nktkas/hyperliquid
Low-level SDK for interacting with Hyperliquid's API in TypeScript.
Features
- Documented ๐ - Comprehensive documentation for all API methods and types
- Tested ๐งช - Tests for all API methods, their parameters and return types
- Universal โ๏ธ - Can use viem or ethers to access a wallet.
- Lightweight ๐ชถ - Depends only on 2 libraries with no subdependencies (29.7 kB), relies on the Web Standard API for everything else.
- Cross-runtime ๐ - Works in Deno, Web, NodeJS, Bun. The same code runs on all platforms.
Installation
For Deno
import * as hyperliquid from "jsr:@nktkas/hyperliquid";
For Web
import * as hyperliquid from "https://esm.sh/jsr/@nktkas/hyperliquid";
For Node.js
npx jsr add @nktkas/hyperliquid
Alternatively, you can use Yarn or pnpm:
- Yarn:
yarn dlx jsr add @nktkas/hyperliquid
- pnpm:
pnpm dlx jsr add @nktkas/hyperliquid
For Bun
bunx jsr add @nktkas/hyperliquid
Usage
Create ExchangeClient
Private key via viem
import * as hyperliquid from "@nktkas/hyperliquid"; import { privateKeyToAccount } from "viem/accounts"; const account = privateKeyToAccount("0x..."); const client = new hyperliquid.ExchangeClient(account);
Private key via ethers
import * as hyperliquid from "@nktkas/hyperliquid"; import { ethers } from "ethers"; const wallet = new ethers.Wallet("0x..."); const client = new hyperliquid.ExchangeClient(wallet);
External wallet (e.g. MetaMask) via viem
import * as hyperliquid from "@nktkas/hyperliquid"; import { createWalletClient, custom } from "viem"; import { arbitrum } from "viem/chains"; const [account] = await window.ethereum!.request({ method: "eth_requestAccounts" }); const walletClient = createWalletClient({ account, chain: arbitrum, transport: http() }); const client = new hyperliquid.ExchangeClient(walletClient);
Create InfoClient
import * as hyperliquid from "@nktkas/hyperliquid"; const client = new hyperliquid.InfoClient(); // You can specify a custom url
Basic example
import * as hyperliquid from "@nktkas/hyperliquid"; // Initialize the exchange client const exchangeClient = new hyperliquid.ExchangeClient(...); // Initialize the info client const infoClient = new hyperliquid.InfoClient(); // Example: Place an order const orderResult = await exchangeClient.order({ orders: [ { a: 0, // Asset index b: true, // Buy order p: "1000", // Price s: "1", // Size r: false, // Not reduce-only t: { limit: { tif: "Gtc" } }, // Good-til-cancelled limit order }, ], grouping: "na", // Just order(s) without grouping }); console.log("Order placed:", orderResult); // Example: Get user's open orders const openOrders = await infoClient.openOrders({ user: "0x..." }); console.log("Open orders:", openOrders);
API Reference
The SDK provides 2 main classes:
ExchangeClient
: For interacting with the exchange API (placing orders, cancelling orders, etc.)InfoClient
: For retrieving information (order book, user positions, etc.)
Each method in these classes is fully documented with TypeScript types and JSDoc comments. Refer to the source code for detailed information on each method and its parameters.
Contributing
Contributions are welcome! Please see the CONTRIBUTING file for guidelines on how to contribute to this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Built and signed on
View transparency logGitHub Actions
Add Package
deno add jsr:@nktkas/hyperliquid
Import symbol
import * as mod from "@nktkas/hyperliquid";
---- OR ----
Import directly with a jsr specifier
import * as mod from "jsr:@nktkas/hyperliquid";
Add Package
npx jsr add @nktkas/hyperliquid
Import symbol
import * as mod from "@nktkas/hyperliquid";
Add Package
yarn dlx jsr add @nktkas/hyperliquid
Import symbol
import * as mod from "@nktkas/hyperliquid";
Add Package
pnpm dlx jsr add @nktkas/hyperliquid
Import symbol
import * as mod from "@nktkas/hyperliquid";
Add Package
bunx jsr add @nktkas/hyperliquid
Import symbol
import * as mod from "@nktkas/hyperliquid";