Skip to content

Clients ​

The SDK exports three clients. Each supports Mainnet and Testnet; public queries do not require a signer.

ClientInterfaceUse
RestClientHTTP requestsQuery data or submit signed actions with await.
WebsocketClientWebSocket subscriptionsReceive updates through event listeners.
WebsocketAPIClientWebSocket requestsCall the REST client's methods over a persistent connection.

RestClient ​

RestClient sends HTTP requests and returns promises.

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

async function main() {
  const client = new RestClient();
  const mids = await client.getAllMids();
  if (mids.BTC === undefined) {
    throw new Error('BTC was not present in the mid-price response.');
  }
  console.log('BTC mid price:', mids.BTC);
}

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

Market data methods work without credentials. Account queries need an account address; signed actions need a private key or signer. See Authentication.

RestClient reference · Market data examples

WebsocketClient ​

Use WebsocketClient for subscriptions. Register message and exception listeners before calling subscribe(). The client opens the required connection automatically.

subscribe() resolves after sending locally. Server acknowledgements arrive on response. See the subscription example for event handling and cleanup.

Call unsubscribe() to remove a topic while keeping the connection, or closeAll() to close all connections. Removing an event listener does not remove the subscription.

WebsocketClient reference · Subscription types

WebsocketAPIClient ​

WebsocketAPIClient extends RestClient and sends the same methods through Hyperliquid's WebSocket POST protocol.

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. For streaming updates, use WebsocketClient subscriptions instead.

WebsocketAPIClient reference · Client configuration

Built by Siebly. Open source SDKs for exchange APIs.