Skip to content

Class: WebsocketClientV2 ​

Extends ​

Constructors ​

Constructor ​

ts
new WebsocketClientV2(options?: WSClientConfigurableOptions, logger?: object): WebsocketClientV2;

Parameters ​

ParameterTypeDescription
options?WSClientConfigurableOptions-
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 ​

WebsocketClientV2

Inherited from ​

BaseWebsocketClient<WsKey, WsRequestOperationBitget<object> // subscribe requests have an "args" parameter with an object within>.constructor

Properties ​

logger ​

ts
logger: object;

error ​

ts
error: (...params: any) => void;
Parameters ​
ParameterType
...paramsany
Returns ​

void

info ​

ts
info: (...params: any) => void;
Parameters ​
ParameterType
...paramsany
Returns ​

void

trace ​

ts
trace: (..._params: any) => void;

Ping/pong events and other raw messages that might be noisy. Enable this while troubleshooting.

Parameters ​
ParameterType
..._paramsany
Returns ​

void

Inherited from ​

BaseWebsocketClient.logger

Methods ​

assertIsAuthenticated() ​

ts
assertIsAuthenticated(wsKey: WsKey): Promise<unknown>;

Promise-driven method to assert that a ws has been successfully authenticated (will await until auth is confirmed)

Parameters ​

ParameterType
wsKeyWsKey

Returns ​

Promise<unknown>

Inherited from ​

BaseWebsocketClient.assertIsAuthenticated


assertIsConnected() ​

ts
assertIsConnected(wsKey: WsKey): Promise<unknown>;

Promise-driven method to assert that a ws has successfully connected (will await until connection is open)

Parameters ​

ParameterType
wsKeyWsKey

Returns ​

Promise<unknown>

Inherited from ​

BaseWebsocketClient.assertIsConnected


close() ​

ts
close(wsKey: WsKey, force?: boolean): void;

Parameters ​

ParameterType
wsKeyWsKey
force?boolean

Returns ​

void

Inherited from ​

BaseWebsocketClient.close


closeAll() ​

ts
closeAll(force?: boolean): void;

Parameters ​

ParameterType
force?boolean

Returns ​

void

Inherited from ​

BaseWebsocketClient.closeAll


connect() ​

ts
connect(
   wsKey: WsKey, 
   customUrl?: string, 
   throwOnError?: boolean
): Promise<WSConnectedResult | undefined>;

Request connection to a specific websocket, instead of waiting for automatic connection.

Parameters ​

ParameterType
wsKeyWsKey
customUrl?string
throwOnError?boolean

Returns ​

Promise<WSConnectedResult | undefined>

Inherited from ​

BaseWebsocketClient.connect


connectAll() ​

ts
connectAll(): Promise<WSConnectedResult | undefined>[];

Request connection of all dependent (public & private) websockets, instead of waiting for automatic connection by library

Returns ​

Promise<WSConnectedResult | undefined>[]

Overrides ​

BaseWebsocketClient.connectAll


emit() ​

ts
emit<U extends keyof WSClientEventMap<TWSKey>>(event: U, ...args: Parameters<WSClientEventMap<WsKey>[U]>): boolean;

Type Parameters ​

Type Parameter
U extends keyof WSClientEventMap<TWSKey>

Parameters ​

ParameterType
eventU
...argsParameters<WSClientEventMap<WsKey>[U]>

Returns ​

boolean

Inherited from ​

BaseWebsocketClient.emit


getCachedMidFlightRequest() ​

ts
getCachedMidFlightRequest(wsKey: WsKey, requestKey: string): 
  | WsRequestOperationBitget<object>
  | undefined;

Parameters ​

ParameterType
wsKeyWsKey
requestKeystring

Returns ​

| WsRequestOperationBitget<object> | undefined

Inherited from ​

BaseWebsocketClient.getCachedMidFlightRequest


getTimeOffsetMs() ​

ts
getTimeOffsetMs(): number;

Returns ​

number

Inherited from ​

BaseWebsocketClient.getTimeOffsetMs


getWsStore() ​

ts
getWsStore(): WsStore<WsKey, WsTopicRequest<string, unknown>>;

Get the WsStore that tracks websockets & topics

Returns ​

WsStore<WsKey, WsTopicRequest<string, unknown>>

Inherited from ​

BaseWebsocketClient.getWsStore


isConnected() ​

ts
isConnected(wsKey: WsKey): boolean;

Parameters ​

ParameterType
wsKeyWsKey

Returns ​

boolean

Inherited from ​

BaseWebsocketClient.isConnected


on() ​

ts
on<U extends keyof WSClientEventMap<TWSKey>>(event: U, listener: WSClientEventMap<WsKey>[U]): this;

Type Parameters ​

Type Parameter
U extends keyof WSClientEventMap<TWSKey>

Parameters ​

ParameterType
eventU
listenerWSClientEventMap<WsKey>[U]

Returns ​

this

Inherited from ​

BaseWebsocketClient.on


removeCachedMidFlightRequest() ​

ts
removeCachedMidFlightRequest(wsKey: WsKey, requestKey: string): void;

Parameters ​

ParameterType
wsKeyWsKey
requestKeystring

Returns ​

void

Inherited from ​

BaseWebsocketClient.removeCachedMidFlightRequest


sendWSAPIRequest() ​

ts
sendWSAPIRequest(): Promise<unknown>;

Returns ​

Promise<unknown>

Deprecrated ​

not supported by Bitget's V2 API offering

Overrides ​

BaseWebsocketClient.sendWSAPIRequest


setTimeOffsetMs() ​

ts
setTimeOffsetMs(newOffset: number): void;

Parameters ​

ParameterType
newOffsetnumber

Returns ​

void

Inherited from ​

BaseWebsocketClient.setTimeOffsetMs


subscribe() ​

ts
subscribe(requests: 
  | WsTopicV2
  | WsTopicRequest<string, unknown>
| WsTopicV2 | WsTopicRequest<string, unknown>[], wsKey: WsKey): Promise<unknown>;

Subscribe to one or more topics. Pass a topic string, an object with topic and optional payload, or an array of these values. Supply the connection key as the second argument. The SDK connects, authenticates when needed and restores subscriptions after reconnecting. Call unsubscribe(requests, wsKey) with the same requests and connection key to remove them.

Parameters ​

ParameterType
requests| WsTopicV2 | WsTopicRequest<string, unknown> | WsTopicV2 | WsTopicRequest<string, unknown>[]
wsKeyWsKey

Returns ​

Promise<unknown>


subscribeTopic() ​

ts
subscribeTopic(
   instType: BitgetInstTypeV2, 
   topic: WsTopicV2, 
   coin?: string
): Promise<unknown>;

Subscribe to a topic

Parameters ​

ParameterTypeDefault valueDescription
instTypeBitgetInstTypeV2undefinedinstrument type (refer to API docs).
topicWsTopicV2undefinedtopic name (e.g. "ticker").
coin?string'default'-

Returns ​

Promise<unknown>

See ​

Subscribe to Classic account updates


tryWsSend() ​

ts
tryWsSend(
   wsKey: WsKey, 
   wsMessage: string, 
   throwExceptions?: boolean
): void;

Parameters ​

ParameterType
wsKeyWsKey
wsMessagestring
throwExceptions?boolean

Returns ​

void

Inherited from ​

BaseWebsocketClient.tryWsSend


unsubscribe() ​

ts
unsubscribe(requests: 
  | WsTopicV2
  | WsTopicRequest<string, unknown>
| WsTopicV2 | WsTopicRequest<string, unknown>[], wsKey: WsKey): Promise<unknown>;

Unsubscribe from one or more topics on the connection selected by wsKey. The topics are removed from the subscription cache and will not be restored after reconnecting.

Parameters ​

ParameterType
requests| WsTopicV2 | WsTopicRequest<string, unknown> | WsTopicV2 | WsTopicRequest<string, unknown>[]
wsKeyWsKey

Returns ​

Promise<unknown>


unsubscribeTopic() ​

ts
unsubscribeTopic(
   instType: BitgetInstTypeV2, 
   topic: WsTopicV2, 
   coin?: string
): Promise<unknown>;

Unsubscribe from a topic

Parameters ​

ParameterTypeDefault valueDescription
instTypeBitgetInstTypeV2undefinedinstrument type (refer to API docs).
topicWsTopicV2undefinedtopic name (e.g. "ticker").
coin?string'default'-

Returns ​

Promise<unknown>

Built by Siebly. Open source SDKs for exchange APIs.