Transports

A Transport is the layer responsible for executing requests to Hyperliquid servers.

HttpTransport

Executes requests via HTTP POST to the Hyperliquid API.

Import

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

Usage

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

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

const mids = await client.allMids();

Parameters

isTestnet (optional)

  • Type: boolean

  • Default: false

Use testnet endpoints instead of mainnet.

timeout (optional)

  • Type: number | null

  • Default: 10000

Request timeout in milliseconds. Set to null to disable.

apiUrl (optional)

  • Type: string | URL

  • Default: https://api.hyperliquid.xyz (mainnet) or https://api.hyperliquid-testnet.xyz (testnet)

Custom API URL for info and exchange requests.

rpcUrl (optional)

  • Type: string | URL

  • Default: https://rpc.hyperliquid.xyz (mainnet) or https://rpc.hyperliquid-testnet.xyz (testnet)

Custom RPC URL for explorer requests (block details, transactions).

fetchOptions (optional)

Custom options passed to the underlying fetcharrow-up-right call.

WebSocketTransport

WebSocket connection for subscriptionsarrow-up-right and POST requestsarrow-up-right.

Import

Usage

Subscription:

POST request:

Reconnection

When connection drops, the transport automatically reconnects with exponential backoff (max 10 seconds) and 3 attempts.

After reconnection, all active subscriptions are automatically restored if resubscribe: true (default).

Parameters

isTestnet (optional)

  • Type: boolean

  • Default: false

Use testnet endpoints instead of mainnet.

timeout (optional)

  • Type: number | null

  • Default: 10000

Request timeout in milliseconds. Set to null to disable.

url (optional)

  • Type: string | URL

  • Default: wss://api.hyperliquid.xyz/ws (mainnet) or wss://api.hyperliquid-testnet.xyz/ws (testnet)

Custom WebSocket URL.

reconnect (optional)

  • Type: object

  • Default: { maxRetries: 3, connectionTimeout: 10000, reconnectionDelay: (attempt) => Math.min(~~(1 << attempt) * 150, 10000) }

Reconnection policy. See ReconnectingWebSocketOptionsarrow-up-right.

resubscribe (optional)

  • Type: boolean

  • Default: true

Automatically restore active subscriptions after reconnection.

Last updated