Skip to content

Clients ​

RestClientV5 returns REST responses as promises. WebsocketClient delivers streaming updates through event listeners.

ClientPurpose
RestClientV5Current V5 market data, account queries and trading endpoints over HTTP.
WebsocketClientPublic and private subscriptions through subscribeV5(), with update events.
WebsocketAPIClientSupported awaitable operations over the Bybit WebSocket API.

REST requests ​

ts
import { RestClientV5 } from 'bybit-api';

async function main() {
  const client = new RestClientV5();
  const response = await client.getTickers({ category: 'spot', symbol: 'BTCUSDT' });
  if (response.retCode !== 0) {
    throw new Error(`Bybit ${response.retCode}: ${response.retMsg}`);
  }
  const ticker = response.result.list[0];
  if (!ticker) throw new Error('BTCUSDT was not present in the ticker response.');
  console.log('BTCUSDT last price:', ticker.lastPrice);
}
main().catch((error) => {
  console.error(error instanceof Error ? error.message : 'Request failed. See the troubleshooting guide.');
  process.exitCode = 1;
});

getTickers() returns an envelope with retCode and result. Check retCode === 0 before reading result.list.

WebSocket subscriptions ​

Register listeners before subscribing with WebsocketClient. The subscription example shows message handling and shutdown.

WebSocket API requests ​

WebsocketAPIClient returns promises for supported Bybit WebSocket API operations. Its method list differs from the REST clients.

Full reference ​

Built by Siebly. Open source SDKs for exchange APIs.