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): 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


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

See ​

Shut down cleanly

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


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 keyof WsAPIWsKeyTopicMap, TWSOperation extends 
  | "ping"
  | "spot.order"
  | "spot.modify"
  | "spot.cancel"
  | "spot.sync_order"
  | "spot.sync_cancel"
  | "margin.order"
  | "margin.cancel"
  | "futures.order"
  | "futures.cancel"
  | "futures.multi_order"
  | "futures.multi_cancel"
  | "uta.amend", TWSParams extends { [K in string | number | symbol]: WsAPITopicRequestParamMap[TWSOperation][K] }, TWSAPIResponse extends unknown = WsAPITopicResponseMap[TWSOperation]>(
   wsKey: TWSKey, 
   operation: TWSOperation, 
   params: TWSParams & object, 
   requestFlags?: WSAPIRequestFlags
): Promise<TWSAPIResponse>;

Type Parameters ​

Type ParameterDefault type
TWSKey extends keyof WsAPIWsKeyTopicMap-
TWSOperation extends | "ping" | "spot.order" | "spot.modify" | "spot.cancel" | "spot.sync_order" | "spot.sync_cancel" | "margin.order" | "margin.cancel" | "futures.order" | "futures.cancel" | "futures.multi_order" | "futures.multi_cancel" | "uta.amend"-
TWSParams extends { [K in string | number | symbol]: WsAPITopicRequestParamMap[TWSOperation][K] }-
TWSAPIResponse extends unknownWsAPITopicResponseMap[TWSOperation]

Parameters ​

ParameterType
wsKeyTWSKey
operationTWSOperation
paramsTWSParams & object
requestFlags?WSAPIRequestFlags

Returns ​

Promise<TWSAPIResponse>


subscribe() ​

ts
subscribe(requests: 
  | string
  | WsTopicRequest<string, any>
  | (
  | string
  | WsTopicRequest<string, any>)[], wsKey: WsKey): void;

Subscribe to one or more topics on the required wsKey connection. Pass a topic string, a { topic, payload } object, or an array of either form. Connection, authentication and resubscription are automatic. Observe response and exception events to confirm acceptance; the method returns void.

Parameters ​

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

Returns ​

void

See ​

Subscribe to market updates


subscribeTopicsForWsKey() ​

ts
subscribeTopicsForWsKey(wsTopicRequests: WsTopicRequestOrStringTopic<string>[], wsKey: WsKey): 
  | boolean
  | Promise<void>
| Promise<WSConnectedResult | 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 call unsubsribeTopicsForWsKey(topics, key).

Parameters ​

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

Returns ​

| boolean | Promise<void> | Promise<WSConnectedResult | 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 ​

ParameterType
wsKeyWsKey
wsMessagestring
throwExceptions?boolean

Returns ​

void

Inherited from ​

BaseWebsocketClient.tryWsSend


unsubscribe() ​

ts
unsubscribe(requests: 
  | string
  | WsTopicRequest<string, any>
  | (
  | string
  | WsTopicRequest<string, any>)[], wsKey: WsKey): void;

Unsubscribe using the same topic requests and required wsKey connection used for subscribe(). Removed topics are also removed from the reconnect subscription cache.

Parameters ​

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

Returns ​

void

Built by Siebly. Open source SDKs for exchange APIs.