Connect to Hyperliquid

The SDK communicates with Hyperliquid through a transport. Choose HTTP or WebSocket and pass it to any client.

HTTP vs WebSocket

The following table compares the two transport types:

HTTP
WebSocket

Best for

Serverless, simple scripts

Real-time data, low latency

Connection

Per-request, stateless

Persistent

Subscriptions

No

Required

HTTP

import { HttpTransport, InfoClient } from "@nktkas/hyperliquid";

const transport = new HttpTransport();
const client = new InfoClient({ transport });

const mids = await client.allMids();

Each request is an independent HTTP POST. No connection state to manage, so it works well in serverless functions, edge workers, or unstable networks.

Endpoints

Two built-in endpoints: apiUrl for info and exchange requests, rpcUrl for explorer requests (block details, transactions). The following table lists the default URLs:

Mainnet
Testnet

apiUrl

https://api.hyperliquid.xyz

https://api.hyperliquid-testnet.xyz

rpcUrl

https://rpc.hyperliquid.xyz

https://rpc.hyperliquid-testnet.xyz

Override when running your own nodearrow-up-right or using a proxy:

Fetch options

Pass custom options to the underlying fetcharrow-up-right call, such as headers, credentials, and cache settings.

WebSocket

The transport maintains a single persistent connection, required for subscriptionsarrow-up-right and lower-latency for high-frequency POST requestsarrow-up-right:

Endpoints

url for info, exchange, and subscription requests. Explorer requests (block details, transactions) need a separate transport on the RPC endpoint. The following table lists the default URLs:

Mainnet
Testnet

url

wss://api.hyperliquid.xyz/ws

wss://api.hyperliquid-testnet.xyz/ws

MAINNET_RPC_WS_URL

wss://rpc.hyperliquid.xyz/ws

TESTNET_RPC_WS_URL

wss://rpc.hyperliquid-testnet.xyz/ws

Override when running your own nodearrow-up-right or using a proxy:

For explorer, pass the RPC constant as url:

Reconnection

When the connection drops, the transport reconnects automatically via @nktkas/rewsarrow-up-right:

See ReconnectingWebSocketOptionsarrow-up-right for all available options.


After reconnection, all active subscriptions are restored automatically. Disable this with resubscribe:

If a subscription fails to restore, its failureSignal is aborted. For details, see Handle failures.

Common options

Testnet

Connect to the Hyperliquid testnet for development and testing:

Timeout

Both transports abort requests after 10 seconds by default. Set a custom timeout or null to disable:

Last updated