Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bybit-api/llms.txt
Use this file to discover all available pages before exploring further.
WebsocketAPIClient wraps the lower-level WebsocketClient.sendWSAPIRequest() method with intuitive, strongly-typed methods for order management over WebSocket. Every method returns a Promise that resolves with the exchange’s typed response — making it a drop-in replacement for the REST order API with significantly lower round-trip latency.
Installation & Import
Constructor
Accepts all
WSClientConfigurableOptions fields (same as WebsocketClient) plus the following WebsocketAPIClient-specific option:Custom logger instance. Defaults to the SDK’s built-in console logger.
Instantiation examples
Authentication is handled automatically. The SDK opens and authenticates the
v5PrivateTrade WebSocket connection the first time you call any order method. Call client.getWSClient().connectWSAPI() beforehand to pre-warm the connection and reduce first-call latency.Methods
getWSClient()
Returns the underlying WebsocketClient instance. Use this to attach custom event listeners, access connection state, or call subscribeV5() for market-data streams.
setTimeOffsetMs(offset)
Manually adjust the time offset (in milliseconds) used when generating request timestamps and authentication signatures. Useful when the SDK detects clock drift that prevents valid signatures.
Time offset in milliseconds to add to
Date.now() when building signed requests.submitNewOrder(params)
Submit a new order over the WebSocket API.
Full order parameters. See the Types reference for the complete
OrderParamsV5 interface.Key fields:| Field | Type | Required | Description |
|---|---|---|---|
category | CategoryV5 | ✅ | 'spot' | 'linear' | 'inverse' | 'option' |
symbol | string | ✅ | Trading pair, e.g. 'BTCUSDT' |
side | 'Buy' | 'Sell' | ✅ | Order side |
orderType | 'Market' | 'Limit' | ✅ | Order type |
qty | string | ✅ | Order quantity as string |
price | string | — | Limit price (required for Limit orders) |
timeInForce | OrderTimeInForceV5 | — | 'GTC' | 'IOC' | 'FOK' | 'PostOnly' |
orderLinkId | string | — | Client-defined order ID |
takeProfit | string | — | Take-profit price |
stopLoss | string | — | Stop-loss price |
reduceOnly | boolean | — | Reduce-only flag |
positionIdx | number | — | Position index (hedge mode) |
amendOrder(params)
Amend an existing open order.
| Field | Type | Required | Description |
|---|---|---|---|
category | CategoryV5 | ✅ | Instrument category |
symbol | string | ✅ | Trading pair |
orderId | string | — | Exchange order ID (orderId or orderLinkId required) |
orderLinkId | string | — | Client order ID |
qty | string | — | New quantity |
price | string | — | New price |
takeProfit | string | — | New take-profit |
stopLoss | string | — | New stop-loss |
triggerPrice | string | — | New trigger price |
cancelOrder(params)
Cancel an existing open order.
| Field | Type | Required | Description |
|---|---|---|---|
category | CategoryV5 | ✅ | Instrument category |
symbol | string | ✅ | Trading pair |
orderId | string | — | Exchange order ID (orderId or orderLinkId required) |
orderLinkId | string | — | Client order ID |
orderFilter | OrderFilterV5 | — | Order filter override |
batchSubmitOrders(category, orders)
Submit multiple orders in a single WS API request.
The instrument category. Only
'option' and 'linear' are supported for batch operations.Array of order parameters. Each object matches
BatchOrderParamsV5 (similar to OrderParamsV5 but without category).batchAmendOrder(category, orders)
Amend multiple orders in a single WS API request.
Instrument category.
Array of amend parameters (symbol, orderId/orderLinkId, and updated fields).
batchCancelOrder(category, orders)
Cancel multiple orders in a single WS API request.
Instrument category.
Array of cancel parameters. Each requires
symbol and either orderId or orderLinkId.WSAPIResponse Structure
Every order method resolves with aWSAPIResponse<TData, TOperation> object.
The connection key that handled this request.
Auto-generated request ID used to correlate the response.
Return code.
0 indicates success. Non-zero values indicate errors — the promise rejects in this case.Human-readable message.
'OK' on success.The operation that produced this response (e.g.
'order.create').Response payload. For single-order operations this is
OrderResultV5. For batch operations it is { list: BatchCreateOrderResultV5[] } etc.Extended info object. Populated for batch operations with per-order status codes via
BatchOrdersRetExtInfoV5.The WebSocket connection ID from Bybit.
Supported WS API Operations
TheWSAPIOperation type and WS_API_Operations array enumerate every supported command.
Error Handling
When the exchange returns a non-zeroretCode, the promise is rejected (not resolved). Always wrap calls in try/catch or use .catch().
Full End-to-End Example
WebsocketClient
Lower-level WebSocket client with
sendWSAPIRequest() and subscription methods.Types Reference
OrderParamsV5, WSAPIResponse, and all related type definitions.
Enums & Constants
WSAPIOperation values and WS_API_Operations array.
RestClientV5
Full REST API reference as an alternative to WS order management.