Skip to content

WebSocket API requests ​

WebsocketAPIClient extends RestClient and sends the same methods through Hyperliquid's WebSocket POST protocol. Public queries do not require a signer; exchange actions still require the appropriate signer.

Use await and try/catch just as you would with a REST API call. The SDK matches responses to requests and manages the WebSocket connection for you. Requests over a persistent WebSocket can offer lower overhead and latency, depending on the exchange, network and workload.

Make a request ​

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

async function main() {
  const client = new WebsocketAPIClient();
  client.on('exception', (event) => console.error(event));

  try {
    const mids = await client.getAllMids();
    console.log(mids.BTC);
  } finally {
    client.close();
  }
}

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

The first request opens the connection. Close the client when finished.

Requests and subscriptions ​

A request returns one result. Use public streams for continuous market data and account updates to follow account and order changes. Request responses do not replace these subscriptions.

Use the account access guide to distinguish unsigned account reads from signed trading actions. For order submissions, keep account updates connected and follow the order management workflow.

Recover an uncertain outcome ​

A connection can fail after an exchange processes a request but before the response arrives. Follow account updates and reconcile uncertain outcomes before retrying an order.

Built by Siebly. Open source SDKs for exchange APIs.