Hyperliquid API SDK
@siebly/hyperliquid-api provides JavaScript and TypeScript clients for Hyperliquid market data, account queries, signed trading actions and WebSocket subscriptions.
Build trading bots and automate your strategies in Node.js, or use real-time market data in a dashboard. Start with a public price request, then add authentication and order handling for your trading workflow.
JavaScript & TypeScript · v1.0.2 · MIT license
Installation
TypeScript definitions are included.
npm install @siebly/hyperliquid-apipnpm add @siebly/hyperliquid-apiyarn add @siebly/hyperliquid-apiChoose your setup
Start with the tools you already use. Each guide includes a complete project, setup commands, expected output and cleanup where applicable.
- Node.js / JavaScript: run plain JavaScript with
importorrequire, without a TypeScript compiler. - Node.js / TypeScript: type-check and compile a Node.js price and subscription script.
- React: display live prices in a React component with effect cleanup, using Vite.
- Vite (plain JavaScript): display prices in a browser page without React.
- Next.js: return a price from a Node.js server Route Handler.
- React Native / Expo: display prices and stop subscriptions on iOS and Android.
- Bun and Deno: run a price and WebSocket script in your chosen runtime.
Each guide includes a downloadable starter generated from the maintained examples and runtime configuration. Runtime compatibility records tested versions and scope.
Usage
RestClient.getAllMids() reads current mid prices without a wallet or private key.
import { RestClient } from '@siebly/hyperliquid-api';
async function main() {
const client = new RestClient();
const mids = await client.getAllMids();
if (mids.BTC === undefined) {
throw new Error('BTC was not present in the mid-price response.');
}
console.log('BTC mid price:', mids.BTC);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});The example prints the BTC mid price. Save it as prices.mjs and run node prices.mjs. See the Node.js quickstart for module formats and example output.
Clients
| Client | Purpose |
|---|---|
RestClient | Query market data and account state, or submit signed actions over HTTP. |
WebsocketClient | Subscribe to market data and account updates. |
WebsocketAPIClient | Call the REST client's methods over a WebSocket connection. |
See Clients for setup and cleanup, or the API reference for methods and types.
Common tasks
| Task | Guide |
|---|---|
| Read prices, order books and candles | Market data |
| Receive market updates | WebSocket subscriptions |
| Query accounts or configure a signer | Authentication |
| Choose a network and set timeouts | Configuration |
Using the SDK
Error handling covers failed requests and rejected orders. Production usage covers retries, recovery and shutdown. Start with Troubleshooting for a specific failure.
For a longer walkthrough, see the Hyperliquid JavaScript tutorial on Siebly.io.