Class: WebsocketClient
Extends
BaseWebsocketClient<WsKey>
Constructors
Constructor
new WebsocketClient(options?: WSClientConfigurableOptions, logger?: object): WebsocketClient;Parameters
| Parameter | Type |
|---|---|
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 |
Returns
WebsocketClient
Inherited from
BaseWebsocketClient<WsKey>.constructor
Methods
assertIsAuthenticated()
assertIsAuthenticated(wsKey: WsKey, forceReauth?: boolean): Promise<unknown>;Wait for the shared authentication exchange, starting it only when needed. Explicit auth calls can force renewal; an in-progress exchange is still shared.
Parameters
| Parameter | Type | Default value |
|---|---|---|
wsKey | WsKey | undefined |
forceReauth? | boolean | false |
Returns
Promise<unknown>
Inherited from
BaseWebsocketClient.assertIsAuthenticated
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): Promise<WSConnectedResult | undefined>;Request connection to a specific websocket, instead of waiting for automatic connection.
Parameters
| Parameter | Type |
|---|---|
wsKey | WsKey |
Returns
Promise<WSConnectedResult | undefined>
Inherited from
BaseWebsocketClient.connect
connectAll()
connectAll(): Promise<(WSConnectedResult | undefined)[]>;Preconnect the original product feeds, preserving the existing connection set. Global connections open on demand and are excluded from this method. Use connect(wsKey) to preconnect a specific feed, or connectWSAPI() for an authenticated Global WS API session.
Returns
Promise<(WSConnectedResult | undefined)[]>
Overrides
BaseWebsocketClient.connectAll
connectWSAPI()
connectWSAPI(): Promise<unknown>;Prepare the Global WS API connection and authenticate before the first private call.
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
getWsStore()
getWsStore(): WsStore<WsKey, WsTopicRequest<string, any>>;Get the WsStore that tracks websockets & topics
Returns
WsStore<WsKey, WsTopicRequest<string, any>>
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
sendWSAPIRequest()
sendWSAPIRequest<TWSKey extends "advTradeGlobalWSAPI", TMethod extends keyof WsAPITopicRequestParamMap>(
wsKey: TWSKey,
method: TMethod,
...args: undefined extends WsAPITopicRequestParamMap[TMethod] ? [params?: WsAPITopicRequestParamMap[TMethod], requestFlags?: WSAPIRequestFlags] : [params: WsAPITopicRequestParamMap[TMethod], requestFlags?: WSAPIRequestFlags]
): Promise<WsAPITopicResponseMap[TMethod]>;Send a Global JSON-RPC method and await its matching reply. Public methods do not require auth. Pending calls reject on API errors, timeout or disconnect. The reply timeout starts after sending; connection/authentication use their own lifecycle handling. public/auth signs automatically and uses the authentication timeout. private/logout resolves on the server's normal close.
Type Parameters
| Type Parameter |
|---|
TWSKey extends "advTradeGlobalWSAPI" |
TMethod extends keyof WsAPITopicRequestParamMap |
Parameters
| Parameter | Type |
|---|---|
wsKey | TWSKey |
method | TMethod |
...args | undefined extends WsAPITopicRequestParamMap[TMethod] ? [params?: WsAPITopicRequestParamMap[TMethod], requestFlags?: WSAPIRequestFlags] : [params: WsAPITopicRequestParamMap[TMethod], requestFlags?: WSAPIRequestFlags] |
Returns
Promise<WsAPITopicResponseMap[TMethod]>
Overrides
BaseWebsocketClient.sendWSAPIRequest
subscribe()
subscribe(requests:
| string
| WsTopicRequest<string, any>
| (
| string
| WsTopicRequest<string, any>)[], wsKey: WsKey): void;Subscribe to one or more topics on the connection selected by wsKey. Pass a topic string, a { topic, payload } object, or an array of either. The SDK opens the selected connection, handles its authentication flow, and restores cached subscriptions after reconnecting. Use unsubscribe(topics, wsKey) to remove them.
Parameters
| Parameter | Type |
|---|---|
requests | | string | WsTopicRequest<string, any> | ( | string | WsTopicRequest<string, any>)[] |
wsKey | WsKey |
Returns
void
See
subscribeTopicsForWsKey()
subscribeTopicsForWsKey(wsTopicRequests: WsTopicRequestOrStringTopic<string>[], wsKey: WsKey): false | Promise<WSConnectedResult | undefined> | undefined;Subscribe to one or more topics on a WS connection (identified by WS Key).
- Topics are automatically cached
- Connections are automatically opened, if not yet connected
- Authentication is automatically handled
- Topics are automatically resubscribed to, if something happens to the connection, unless you unsubscribe from the topics.
Parameters
| Parameter | Type | Description |
|---|---|---|
wsTopicRequests | WsTopicRequestOrStringTopic<string>[] | array of topics to subscribe to |
wsKey | WsKey | ws key referring to the ws connection these topics should be subscribed on |
Returns
false | Promise<WSConnectedResult | undefined> | undefined
Inherited from
BaseWebsocketClient.subscribeTopicsForWsKey
tryWsSend()
tryWsSend(
wsKey: WsKey,
wsMessage: string,
throwExceptions?: boolean
): void;Try sending a string event on a WS connection (identified by the WS Key)
Parameters
| Parameter | Type | Default value |
|---|---|---|
wsKey | WsKey | undefined |
wsMessage | string | undefined |
throwExceptions? | boolean | false |
Returns
void
Inherited from
BaseWebsocketClient.tryWsSend
unsubscribe()
unsubscribe(requests:
| string
| WsTopicRequest<string, any>
| (
| string
| WsTopicRequest<string, any>)[], wsKey: WsKey): void;Unsubscribe from one or more topics on the connection selected by wsKey. Topics are removed from the local cache even when disconnected, so reconnecting does not restore them.
Parameters
| Parameter | Type |
|---|---|
requests | | string | WsTopicRequest<string, any> | ( | string | WsTopicRequest<string, any>)[] |
wsKey | WsKey |
Returns
void