Use this file to discover all available pages before exploring further.
Private WebSocket streams deliver real-time account updates: open positions, order status changes, trade executions, wallet balance movements, and options greeks. All private topics share a single authenticated connection at wss://stream.bybit.com/v5/private. You provide your key and secret in the constructor; authentication is handled automatically before the first private subscription is sent.
Supply credentials in the WebsocketClient constructor. The SDK signs and sends an auth frame as soon as a private connection is needed — you do not call any auth method manually:
import { WebsocketClient } from 'bybit-api';const wsClient = new WebsocketClient({ key: process.env.API_KEY, secret: process.env.API_SECRET, // testnet: true, // Use testnet.bybit.com // demoTrading: false, // Note: demo trading only supports consuming events});
You can monitor authentication events using the authenticated event:
For private topics, the category argument passed to subscribeV5() is ignored because all private topics share a single endpoint regardless of product category. You can pass any category string (e.g. 'linear') as a placeholder — the SDK routes the subscription to v5Private automatically.
A low-latency execution stream that delivers a reduced-field subset of execution data. Use this when execution latency matters more than the full detail available on execution. Category-specific variants (execution.fast.linear, execution.fast.inverse, execution.fast.spot, execution.fast.option) are also supported.
wsClient.on('update', (data) => { if (data.topic === 'execution.fast' || data.topic.startsWith('execution.fast.')) { for (const exec of data.data) { // exec: { category, symbol, execId, execPrice, execQty, // orderId, isMaker, orderLinkId, side, execTime, seq } console.log(`Fast execution: ${exec.symbol} ${exec.execQty} @ ${exec.execPrice}`); } }});// Subscribe to the combined fast execution stream (all categories)wsClient.subscribeV5('execution.fast', 'linear');// Or subscribe to a category-specific fast streamwsClient.subscribeV5('execution.fast.linear', 'linear');wsClient.subscribeV5('execution.fast.spot', 'spot');wsClient.subscribeV5('execution.fast.inverse', 'inverse');wsClient.subscribeV5('execution.fast.option', 'option');
Pushed when options greeks change for the account. Only meaningful for accounts holding option positions.
wsClient.on('update', (data) => { if (data.topic === 'greeks') { for (const greek of data.data) { // greek: { baseCoin, totalDelta, totalGamma, totalVega, totalTheta } console.log( `Greeks for ${greek.baseCoin}: delta=${greek.totalDelta} gamma=${greek.totalGamma}`, ); } }});// The category value is ignored for private topics — use any valid stringwsClient.subscribeV5('greeks', 'option');
Using Public and Private Topics on the Same Client
A single WebsocketClient instance can hold both public and private subscriptions at the same time. The SDK automatically routes each topic to its correct connection:
import { WebsocketClient } from 'bybit-api';const wsClient = new WebsocketClient({ key: process.env.API_KEY, secret: process.env.API_SECRET,});wsClient.on('update', (data) => { switch (true) { case data.topic === 'position': console.log('Position:', data.data); break; case data.topic === 'order': console.log('Order:', data.data); break; case data.topic === 'wallet': console.log('Wallet:', data.data); break; case data.topic.startsWith('orderbook'): console.log('Orderbook:', data.topic, data.type); break; case data.topic.startsWith('tickers'): console.log('Ticker:', data.topic, data.data); break; }});wsClient.on('open', ({ wsKey }) => console.log('Connected:', wsKey));wsClient.on('authenticated', ({ wsKey }) => console.log('Authenticated:', wsKey));wsClient.on('exception', (err) => console.error('Exception:', err));wsClient.on('reconnect', ({ wsKey }) => console.log('Reconnecting:', wsKey));wsClient.on('reconnected', ({ wsKey }) => console.log('Reconnected:', wsKey));// Public topics — routed to v5LinearPublic, v5SpotPublic, etc.wsClient.subscribeV5('orderbook.50.BTCUSDT', 'linear');wsClient.subscribeV5('tickers.BTCUSDT', 'spot');// Private topics — all routed to v5Private, authenticated automaticallywsClient.subscribeV5('position', 'linear');wsClient.subscribeV5(['order', 'wallet', 'greeks'], 'linear');wsClient.subscribeV5('execution', 'linear');