Skip to content

Configuration ​

Pass options when constructing a client. Network selection and signing options belong in the first argument; RestClient accepts HTTP request options in a second argument.

Networks ​

All three clients accept testnet: true. Set it on each client so requests and subscriptions use the same network.

ts
import { RestClient } from '@siebly/hyperliquid-api';

async function main() {
  const client = new RestClient({ testnet: true });
  const mids = await client.getAllMids();
  console.log(mids.BTC);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Mainnet is the default. When using a custom endpoint, RestClientOptions.baseUrl overrides the HTTP URL and WebsocketClientOptions.wsUrl overrides the WebSocket URL. Set testnet to match that endpoint so signed actions use the correct network.

HTTP requests ​

The default HTTP request timeout is 10,000 ms. Change it through the second constructor argument:

ts
import { RestClient } from '@siebly/hyperliquid-api';

const client = new RestClient(
  { testnet: true },
  { timeout: 20_000 },
);

client.getAllMids().then(console.log).catch(console.error);

The second argument accepts RestClientNetworkOptions, including custom headers and Axios network options. HTTP keep-alive is enabled by default and can be disabled with keepAlive: false in the first argument. HTTP requests are not retried automatically.

WebSocket connections ​

WebsocketClient and WebsocketAPIClient accept connection and request timeouts in the first argument. This example allows 5 seconds to connect and 20 seconds for a request, including connection setup.

ts
import { WebsocketAPIClient } from '@siebly/hyperliquid-api';

async function main() {
  const client = new WebsocketAPIClient({
    testnet: true,
    connectionTimeout: 5_000,
    requestTimeoutMs: 20_000,
  });
  client.on('exception', console.error);

  try {
    console.log(await client.getAllMids());
  } finally {
    client.close();
  }
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
OptionDefaultDescription
autoReconnecttrueReconnect after an unexpected disconnect.
connectionTimeout1,000 msMaximum time to open a connection.
requestTimeoutMs10,000 msMaximum duration of a WebSocket request, including connection setup.
reconnectTimeout500 msInitial reconnect delay.
maxReconnectTimeout10,000 msMaximum reconnect delay.

The delay increases with repeated connection failures. See WebSocket subscriptions for subscription restoration and WebsocketClientOptions for heartbeat and other options.

Accounts and signing ​

Use accountAddress for account queries and privateKey or signer for signed actions. See Authentication for API wallets, vault addresses and address precedence.

Browser usage ​

Browser bundles support public REST requests and subscriptions. REST access depends on the exchange's CORS rules. Replace the examples' Node.js environment variables and shutdown handlers when adapting them for a browser. For wallet access, use a custom signer.

Configuration reference ​

ConfigurationReference
REST, accounts, signers and networkRestClientOptions
Socket timeouts, heartbeats and reconnectsWebsocketClientOptions
Awaitable WebSocket request clientWebsocketAPIClientOptions

Built by Siebly. Open source SDKs for exchange APIs.