Skip to content

Class: WebsocketClient ​

Extends ​

  • BaseWebsocketClient<WsKey>

Constructors ​

Constructor ​

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

Parameters ​

ParameterType
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() ​

ts
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 ​

ParameterTypeDefault value
wsKeyWsKeyundefined
forceReauth?booleanfalse

Returns ​

Promise<unknown>

Inherited from ​

BaseWebsocketClient.assertIsAuthenticated


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): Promise<WSConnectedResult | undefined>;

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

Parameters ​

ParameterType
wsKeyWsKey

Returns ​

Promise<WSConnectedResult | undefined>

Inherited from ​

BaseWebsocketClient.connect


connectAll() ​

ts
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() ​

ts
connectWSAPI(): Promise<unknown>;

Prepare the Global WS API connection and authenticate before the first private call.

Returns ​

Promise<unknown>


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


getWsStore() ​

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

Get the WsStore that tracks websockets & topics

Returns ​

WsStore<WsKey, WsTopicRequest<string, any>>

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


sendWSAPIRequest() ​

ts
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 ​

ParameterType
wsKeyTWSKey
methodTMethod
...argsundefined extends WsAPITopicRequestParamMap[TMethod] ? [params?: WsAPITopicRequestParamMap[TMethod], requestFlags?: WSAPIRequestFlags] : [params: WsAPITopicRequestParamMap[TMethod], requestFlags?: WSAPIRequestFlags]

Returns ​

Promise<WsAPITopicResponseMap[TMethod]>

Overrides ​

BaseWebsocketClient.sendWSAPIRequest


subscribe() ​

ts
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 ​

ParameterType
requests| string | WsTopicRequest<string, any> | ( | string | WsTopicRequest<string, any>)[]
wsKeyWsKey

Returns ​

void

See ​

Advanced Trade subscriptions


subscribeTopicsForWsKey() ​

ts
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 ​

ParameterTypeDescription
wsTopicRequestsWsTopicRequestOrStringTopic<string>[]array of topics to subscribe to
wsKeyWsKeyws key referring to the ws connection these topics should be subscribed on

Returns ​

false | Promise<WSConnectedResult | undefined> | undefined

Inherited from ​

BaseWebsocketClient.subscribeTopicsForWsKey


tryWsSend() ​

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

Try sending a string event on a WS connection (identified by the WS Key)

Parameters ​

ParameterTypeDefault value
wsKeyWsKeyundefined
wsMessagestringundefined
throwExceptions?booleanfalse

Returns ​

void

Inherited from ​

BaseWebsocketClient.tryWsSend


unsubscribe() ​

ts
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 ​

ParameterType
requests| string | WsTopicRequest<string, any> | ( | string | WsTopicRequest<string, any>)[]
wsKeyWsKey

Returns ​

void

Built by Siebly. Open source SDKs for exchange APIs.