Class: WebsocketClientV3
WebSocket client dedicated to the unified account (V3) WebSockets.
Your Bitget account needs to be upgraded to unified account mode, to use the account-level WebSocket topics.
Extends
BaseWebsocketClient<WsKey,WsRequestOperationBitget<object>>
Constructors
Constructor
new WebsocketClientV3(options?: WSClientConfigurableOptions, logger?: object): WebsocketClientV3;Parameters
| Parameter | Type | Description |
|---|---|---|
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) => void | Ping/pong events and other raw messages that might be noisy. Enable this while troubleshooting. |
Returns
WebsocketClientV3
Inherited from
BaseWebsocketClient<WsKey, WsRequestOperationBitget<object> // subscribe requests have an "args" parameter with an object within>.constructor
Properties
logger
logger: object;error
error: (...params: any) => void;Parameters
| Parameter | Type |
|---|---|
...params | any |
Returns
void
info
info: (...params: any) => void;Parameters
| Parameter | Type |
|---|---|
...params | any |
Returns
void
trace
trace: (..._params: any) => void;Ping/pong events and other raw messages that might be noisy. Enable this while troubleshooting.
Parameters
| Parameter | Type |
|---|---|
..._params | any |
Returns
void
Inherited from
BaseWebsocketClient.logger
Methods
assertIsAuthenticated()
assertIsAuthenticated(wsKey: WsKey): Promise<unknown>;Promise-driven method to assert that a ws has been successfully authenticated (will await until auth is confirmed)
Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
Returns
Promise<unknown>
Inherited from
BaseWebsocketClient.assertIsAuthenticated
assertIsConnected()
assertIsConnected(wsKey: WsKey): Promise<unknown>;Promise-driven method to assert that a ws has successfully connected (will await until connection is open)
Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
Returns
Promise<unknown>
Inherited from
BaseWebsocketClient.assertIsConnected
close()
close(wsKey: WsKey, force?: boolean): void;Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
force? | boolean |
Returns
void
Inherited from
BaseWebsocketClient.close
closeAll()
closeAll(force?: boolean): void;Parameters
| Parameter | Type |
|---|---|
force? | boolean |
Returns
void
Inherited from
BaseWebsocketClient.closeAll
connect()
connect(
wsKey: WsKey,
customUrl?: string,
throwOnError?: boolean
): Promise<WSConnectedResult | undefined>;Request connection to a specific websocket, instead of waiting for automatic connection.
Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
customUrl? | string |
throwOnError? | boolean |
Returns
Promise<WSConnectedResult | undefined>
Inherited from
BaseWebsocketClient.connect
connectAll()
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
connectWSAPI()
connectWSAPI(): Promise<unknown>;Ensures the WS API connection is active and ready.
You do not need to call this, but if you call this before making any WS API requests, it can accelerate the first request (by preparing the connection in advance).
Returns
Promise<unknown>
emit()
emit<U extends keyof WSClientEventMap<TWSKey>>(event: U, ...args: Parameters<WSClientEventMap<WsKey>[U]>): boolean;Type Parameters
| Type Parameter |
|---|
U extends keyof WSClientEventMap<TWSKey> |
Parameters
| Parameter | Type |
|---|---|
event | U |
...args | Parameters<WSClientEventMap<WsKey>[U]> |
Returns
boolean
Inherited from
BaseWebsocketClient.emit
getCachedMidFlightRequest()
getCachedMidFlightRequest(wsKey: WsKey, requestKey: string):
| WsRequestOperationBitget<object>
| undefined;Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
requestKey | string |
Returns
| WsRequestOperationBitget<object> | undefined
Inherited from
BaseWebsocketClient.getCachedMidFlightRequest
getTimeOffsetMs()
getTimeOffsetMs(): number;Returns
number
Inherited from
BaseWebsocketClient.getTimeOffsetMs
getWsStore()
getWsStore(): WsStore<WsKey, WsTopicRequest<string, unknown>>;Get the WsStore that tracks websockets & topics
Returns
WsStore<WsKey, WsTopicRequest<string, unknown>>
Inherited from
BaseWebsocketClient.getWsStore
isConnected()
isConnected(wsKey: WsKey): boolean;Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
Returns
boolean
Inherited from
BaseWebsocketClient.isConnected
on()
on<U extends keyof WSClientEventMap<TWSKey>>(event: U, listener: WSClientEventMap<WsKey>[U]): this;Type Parameters
| Type Parameter |
|---|
U extends keyof WSClientEventMap<TWSKey> |
Parameters
| Parameter | Type |
|---|---|
event | U |
listener | WSClientEventMap<WsKey>[U] |
Returns
this
Inherited from
BaseWebsocketClient.on
removeCachedMidFlightRequest()
removeCachedMidFlightRequest(wsKey: WsKey, requestKey: string): void;Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
requestKey | string |
Returns
void
Inherited from
BaseWebsocketClient.removeCachedMidFlightRequest
sendWSAPIRequest()
sendWSAPIRequest<TWSKey extends "v3Private", TWSOperation extends WSAPIOperation, TWSParams extends
| CancelOrderRequestV3
| ModifyOrderRequestV3
| WSAPIPlaceOrderRequestV3
| WSAPIPlaceOrderRequestV3[]
| CancelOrderRequestV3[]
| ModifyOrderRequestV3[], TWSAPIResponse extends
| WSAPIResponse<[WSAPIPlaceOrderResponseV3], "place-order">
| WSAPIResponse<WSAPIPlaceOrderResponseV3[], "batch-place">
| WSAPIResponse<[CancelOrderResponseV3], "cancel-order">
| WSAPIResponse<CancelOrderResponseV3[], "batch-cancel">
| WSAPIResponse<[ModifyOrderResponseV3], "modify-order">
| WSAPIResponse<ModifyOrderResponseV3[], "batch-modify"> = WsAPIOperationResponseMap[TWSOperation]>(
wsKey: WsKey,
operation: TWSOperation,
category: BitgetInstTypeV3,
params: TWSParams & object,
requestFlags?: WSAPIRequestFlags
): Promise<TWSAPIResponse>;V3/UTA supports order placement via WebSockets. This is the WS API: https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel
Type Parameters
| Type Parameter | Default type |
|---|---|
TWSKey extends "v3Private" | - |
TWSOperation extends WSAPIOperation | - |
TWSParams extends | CancelOrderRequestV3 | ModifyOrderRequestV3 | WSAPIPlaceOrderRequestV3 | WSAPIPlaceOrderRequestV3[] | CancelOrderRequestV3[] | ModifyOrderRequestV3[] | - |
TWSAPIResponse extends | WSAPIResponse<[WSAPIPlaceOrderResponseV3], "place-order"> | WSAPIResponse<WSAPIPlaceOrderResponseV3[], "batch-place"> | WSAPIResponse<[CancelOrderResponseV3], "cancel-order"> | WSAPIResponse<CancelOrderResponseV3[], "batch-cancel"> | WSAPIResponse<[ModifyOrderResponseV3], "modify-order"> | WSAPIResponse<ModifyOrderResponseV3[], "batch-modify"> | WsAPIOperationResponseMap[TWSOperation] |
Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
operation | TWSOperation |
category | BitgetInstTypeV3 |
params | TWSParams & object |
requestFlags? | WSAPIRequestFlags |
Returns
Promise<TWSAPIResponse>
a promise that resolves/rejects when a matching response arrives
Overrides
BaseWebsocketClient.sendWSAPIRequest
setTimeOffsetMs()
setTimeOffsetMs(newOffset: number): void;Parameters
| Parameter | Type |
|---|---|
newOffset | number |
Returns
void
Inherited from
BaseWebsocketClient.setTimeOffsetMs
subscribe()
subscribe<TWSPayload extends object>(requests:
| WsTopicV3
| WsTopicRequest<WsTopicV3, TWSPayload>
| WsTopicV3 | WsTopicRequest<WsTopicV3, TWSPayload>[], 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.
Type Parameters
| Type Parameter |
|---|
TWSPayload extends object |
Parameters
| Parameter | Type |
|---|---|
requests | | WsTopicV3 | WsTopicRequest<WsTopicV3, TWSPayload> | WsTopicV3 | WsTopicRequest<WsTopicV3, TWSPayload>[] |
wsKey | WsKey |
Returns
Promise<unknown>
See
Subscribe to public market data
tryWsSend()
tryWsSend(
wsKey: WsKey,
wsMessage: string,
throwExceptions?: boolean
): void;Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
wsMessage | string |
throwExceptions? | boolean |
Returns
void
Inherited from
BaseWebsocketClient.tryWsSend
unsubscribe()
unsubscribe<TWSPayload extends object>(requests:
| WsTopicV3
| WsTopicRequest<WsTopicV3, TWSPayload>
| WsTopicV3 | WsTopicRequest<WsTopicV3, TWSPayload>[], 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.
Type Parameters
| Type Parameter |
|---|
TWSPayload extends object |
Parameters
| Parameter | Type |
|---|---|
requests | | WsTopicV3 | WsTopicRequest<WsTopicV3, TWSPayload> | WsTopicV3 | WsTopicRequest<WsTopicV3, TWSPayload>[] |
wsKey | WsKey |
Returns
Promise<unknown>