Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Node.js & JavaScript SDK for Hyperliquid REST APIs & WebSockets
# Hyperliquid JavaScript & TypeScript SDK for REST APIs & WebSockets

[![Build & Test](https://github.com/sieblyio/hyperliquid-api/actions/workflows/e2etest.yml/badge.svg?branch=main)](https://github.com/sieblyio/hyperliquid-api/actions/workflows/e2etest.yml)
[![npm version](https://img.shields.io/npm/v/%40siebly%2Fhyperliquid-api)][1]
Expand All @@ -19,7 +19,7 @@

[1]: https://www.npmjs.com/package/@siebly/hyperliquid-api

Professional Node.js, JavaScript & TypeScript SDK for the Hyperliquid REST APIs, WebSocket APIs & WebSocket Events.
Professional Node.js, JavaScript & TypeScript SDK for the Hyperliquid REST APIs, WebSocket APIs & WebSocket Events. It runs on Node.js 22+, Bun, Deno, browsers, React Native and Cloudflare Workers.

Take a look at our dedicated [HyperLiquid API quickstart guides for major frameworks and JavaScript runtimes](#frameworks--quickstart-guides).

Expand Down Expand Up @@ -55,6 +55,7 @@ Take a look at our dedicated [HyperLiquid API quickstart guides for major framew

- [Installation](#installation)
- [Frameworks & Quickstart Guides](#frameworks--quickstart-guides)
- [Coming from Other SDKs or AI-Written Code](#coming-from-other-sdks-or-ai-written-code)
- [Documentation](#documentation)
- [Issues & Discussion](#issues--discussion)
- [Related Projects](#related-projects)
Expand Down Expand Up @@ -89,10 +90,15 @@ Take a look at our dedicated [HyperLiquid API quickstart guides for major framew
## Installation

```bash
# Node.js 22 or newer, and browser (Vite, React, Next.js), React Native (Expo) and Cloudflare Workers projects
npm install @siebly/hyperliquid-api
```

Node.js 22 or newer is supported.
# Bun
bun add @siebly/hyperliquid-api

# Deno 2
deno add npm:@siebly/hyperliquid-api
```

### Frameworks & Quickstart Guides

Expand All @@ -108,6 +114,30 @@ Our complete Hyperliquid SDK supports all the major JavaScript runtimes. For max

Refer to [runtime compatibility](https://sieblyio.github.io/docs/hyperliquid/compatibility.html) for a complete list of runtimes that we've actively tested, including setup guides.

### Coming from Other SDKs or AI-Written Code

Code written from memory by AI assistants, or ported from other Hyperliquid or exchange SDKs, often gets these details wrong:

- **No API key or secret.** Hyperliquid signs with a wallet key. Pass `privateKey` (your API wallet key) and `accountAddress` (the master account or subaccount it trades for). Options such as `key`, `secret` or `apiKey` do not exist. For an external wallet, pass a [custom signer](#custom-signer).
- **Prices and sizes are strings.** Use decimal strings such as `price: '95000'` and `size: '0.001'`. JavaScript numbers are not accepted for decimal fields.
- **Method names follow the REST client, not the raw request type.**

| Raw Info or Exchange type | `RestClient` method |
| ------------------------- | ------------------------------------------------------------------------------------- |
| `allMids` | `getAllMids()` |
| `l2Book` | `getOrderBook()` |
| `meta` | `getPerpMetadata()` |
| `metaAndAssetCtxs` | `getPerpAssetContexts()` |
| `clearinghouseState` | `getPerpAccountSummary()` |
| `openOrders` | `getOpenOrders()` |
| `userFills` | `getUserFills()` |
| `candleSnapshot` | `getCandles()` |
| `order` | `submitLimitOrder()`, `submitMarketOrder()` or `submitOrder()` for native order wires |
| `cancel` | `cancelOrders()` |

- **`GTC` vs `Gtc`.** The `submitLimitOrder()` helper takes `timeInForce: 'GTC'` or `'IOC'` (or `postOnly: true`). The native order wire passed to `submitOrder()` uses Hyperliquid's own casing: `t: { limit: { tif: 'Gtc' } }`, `'Ioc'` or `'Alo'`.
- **Testnet is a client option.** Set `testnet: true` on each client. Changing only a URL does not change the signing network.

## Documentation

The [Hyperliquid SDK documentation](https://sieblyio.github.io/docs/hyperliquid/) page covers complete guidance on installation, client setup, public APIs (e.g. market data), private APIs (e.g. trading, order management), and WebSockets (subscriptions, WebSocket API, authentication, etc).
Expand Down
12 changes: 6 additions & 6 deletions docs/HYPERLIQUID_SDK_QUICKSTART_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Node.js 22 or newer is supported. Every example below is plain JavaScript.

## Set up a wallet and API wallet

Public market data and account-state reads do not require a private key. Hyperliquid account state is queried by public address.
With `@siebly/hyperliquid-api`, public market data and account-state reads do not require a private key. Hyperliquid account state is queried by public address.

Orders and other Exchange actions require a signer. For an automated process, create and approve an API wallet from the [Hyperliquid API page](https://app.hyperliquid.xyz/API). Hyperliquid also calls these agent wallets.

Expand Down Expand Up @@ -509,7 +509,7 @@ Asset IDs differ across Mainnet and Testnet. Resolve them against the same netwo

## Build with Hyperliquid WebSocket streams

`WebsocketClient` manages connections, JSON parsing, heartbeats, reconnects, and resubscriptions. Subscriptions are objects that match Hyperliquid's documented channel types.
`WebsocketClient` from `@siebly/hyperliquid-api` manages connections, JSON parsing, heartbeats, reconnects, and resubscriptions. Subscriptions are objects that match Hyperliquid's documented channel types.

### 4. Subscribe to public market data

Expand Down Expand Up @@ -700,7 +700,7 @@ Every lifecycle, message, response, and exception event includes `wsKey`. Most s

## Place and manage Testnet orders

Use Hyperliquid Testnet to run the following workflows. Create and approve an API wallet from the [Testnet API page](https://app.hyperliquid-testnet.xyz/API), fund the account from the [Testnet faucet](https://app.hyperliquid-testnet.xyz/drip), then set `HYPERLIQUID_TESTNET_API_WALLET_KEY` and `HYPERLIQUID_TESTNET_ACCOUNT_ADDRESS`. The faucet currently requires the same address to have deposited on Mainnet.
These workflows use `RestClient` from `@siebly/hyperliquid-api` (`npm install @siebly/hyperliquid-api`) on Hyperliquid Testnet. Create and approve an API wallet from the [Testnet API page](https://app.hyperliquid-testnet.xyz/API), fund the account from the [Testnet faucet](https://app.hyperliquid-testnet.xyz/drip), then set `HYPERLIQUID_TESTNET_API_WALLET_KEY` and `HYPERLIQUID_TESTNET_ACCOUNT_ADDRESS`. The faucet currently requires the same address to have deposited on Mainnet.

The SDK signs Exchange actions with the API wallet and sends account queries for the configured account address. It lowercases EVM addresses and formats action fields in the order required by Hyperliquid's signing rules.

Expand Down Expand Up @@ -1008,7 +1008,7 @@ The account needs enough Testnet USDC to reserve the order. A Spot sell needs th

### Market orders, closing positions, and leverage

`submitMarketOrder()` is an immediate-or-cancel limit order with a protection price. When `price` is omitted, the SDK loads the current midpoint, applies `maxSlippage`, rounds the protection price to Hyperliquid's rules, and rounds size down to `szDecimals`.
`submitMarketOrder()` in `@siebly/hyperliquid-api` is an immediate-or-cancel limit order with a protection price. When `price` is omitted, the SDK loads the current midpoint, applies `maxSlippage`, rounds the protection price to Hyperliquid's rules, and rounds size down to `szDecimals`.

Call `submitMarketOrder()` with `symbol`, `side`, `size`, and an optional `maxSlippage`. For example, a BTC buy can use `{ symbol: 'BTC', side: 'buy', size: '0.001', maxSlippage: 0.01 }`.

Expand All @@ -1024,7 +1024,7 @@ These are signed production actions on Mainnet and signed test actions on Testne

## Send Info and Exchange requests with the WebSocket API

`WebsocketAPIClient` exposes the same promise-based methods as `RestClient`, but sends supported Info and Exchange requests through Hyperliquid's WebSocket POST protocol.
`WebsocketAPIClient` from `@siebly/hyperliquid-api` exposes the same promise-based methods as `RestClient`, but sends supported Info and Exchange requests through Hyperliquid's WebSocket POST protocol.

The SDK opens the connection when needed, assigns a unique request ID, matches the response to the promise, and rejects protocol errors. The raw `id` and response wrapper do not need to be managed by application code.

Expand Down Expand Up @@ -1200,7 +1200,7 @@ An order-command response acknowledges the action and reports its immediate stat

## Explore more REST API methods

`RestClient` covers Hyperliquid's wider Info and Exchange surfaces. The following groups are a starting map rather than a complete list.
`RestClient` in `@siebly/hyperliquid-api` covers Hyperliquid's wider Info and Exchange surfaces. The following groups are a starting map rather than a complete list.

### Market and account information

Expand Down
Loading