Skip to content

Class: WebsocketAPIClient ​

This is a minimal Websocket API wrapper around the WebsocketClient.

Some methods support passing in a custom "wsKey". This is a reference to which WS connection should be used to transmit that message. This is only useful if you wish to use an alternative wss domain that is supported by the SDK.

Note: To use testnet, don't set the wsKey - use testnet: true in the constructor instead.

Note: You can also directly use the sendWSAPIRequest() method to make WS API calls, but some may find the below methods slightly more intuitive.

Refer to the WS API promises example for a more detailed example on using sendWSAPIRequest() directly: https://github.com/tiagosiebler/bybit-api/blob/master/examples/ws-api-raw-promises.ts

Constructors ​

Constructor ​

ts
new WebsocketAPIClient(options?: WSClientConfigurableOptions & Partial<WSAPIClientConfigurableOptions>, logger?: object): WebsocketAPIClient;

Parameters ​

ParameterTypeDescription
options?WSClientConfigurableOptions & Partial<WSAPIClientConfigurableOptions>-
logger?{ error: (...params: any) => void; info: (...params: any) => void; trace: (..._params: any) => void; }-
logger.error?(...params: any) => void-
logger.info?(...params: any) => void-
logger.trace?(..._params: any) => voidPing/pong events and other raw messages that might be noisy. Enable this while troubleshooting.

Returns ​

WebsocketAPIClient

Methods ​

amendOrder() ​

ts
amendOrder(params: AmendOrderParamsV5): Promise<WSAPIResponse<OrderResultV5, "order.amend", {
}>>;

Amend an order

Parameters ​

ParameterTypeDescription
paramsAmendOrderParamsV5-

Returns ​

Promise<WSAPIResponse<OrderResultV5, "order.amend", { }>>


batchAmendOrder() ​

ts
batchAmendOrder(category: "linear" | "option", orders: BatchAmendOrderParamsV5[]): Promise<WSAPIResponse<{
  list: BatchAmendOrderResultV5[];
}, "order.amend-batch", BatchOrdersRetExtInfoV5>>;

Batch amend orders

Parameters ​

ParameterType
category"linear" | "option"
ordersBatchAmendOrderParamsV5[]

Returns ​

Promise<WSAPIResponse<{ list: BatchAmendOrderResultV5[]; }, "order.amend-batch", BatchOrdersRetExtInfoV5>>


batchCancelOrder() ​

ts
batchCancelOrder(category: "linear" | "option", orders: BatchCancelOrderParamsV5[]): Promise<WSAPIResponse<{
  list: BatchCancelOrderResultV5[];
}, "order.cancel-batch", BatchOrdersRetExtInfoV5>>;

Batch cancel orders

Parameters ​

ParameterType
category"linear" | "option"
ordersBatchCancelOrderParamsV5[]

Returns ​

Promise<WSAPIResponse<{ list: BatchCancelOrderResultV5[]; }, "order.cancel-batch", BatchOrdersRetExtInfoV5>>


batchSubmitOrders() ​

ts
batchSubmitOrders(category: "linear" | "option", orders: BatchOrderParamsV5[]): Promise<WSAPIResponse<{
  list: BatchCreateOrderResultV5[];
}, "order.create-batch", BatchOrdersRetExtInfoV5>>;

Batch submit orders

Parameters ​

ParameterType
category"linear" | "option"
ordersBatchOrderParamsV5[]

Returns ​

Promise<WSAPIResponse<{ list: BatchCreateOrderResultV5[]; }, "order.create-batch", BatchOrdersRetExtInfoV5>>


cancelOrder() ​

ts
cancelOrder(params: CancelOrderParamsV5): Promise<WSAPIResponse<OrderResultV5, "order.cancel", {
}>>;

Cancel an order

Parameters ​

ParameterTypeDescription
paramsCancelOrderParamsV5-

Returns ​

Promise<WSAPIResponse<OrderResultV5, "order.cancel", { }>>


getWSClient() ​

ts
getWSClient(): WebsocketClient;

Returns ​

WebsocketClient


setTimeOffsetMs() ​

ts
setTimeOffsetMs(newOffset: number): void;

Parameters ​

ParameterType
newOffsetnumber

Returns ​

void


submitNewOrder() ​

ts
submitNewOrder(params: OrderParamsV5): Promise<WSAPIResponse<OrderResultV5, "order.create", {
}>>;

Submit a new order

Parameters ​

ParameterTypeDescription
paramsOrderParamsV5-

Returns ​

Promise<WSAPIResponse<OrderResultV5, "order.create", { }>>

Built by Siebly. Open source SDKs for exchange APIs.