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): 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
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
See
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
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 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 Parameter | Default 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 unknown | WsAPITopicResponseMap[TWSOperation] |
Parameters
| Parameter | Type |
|---|---|
wsKey | TWSKey |
operation | TWSOperation |
params | TWSParams & object |
requestFlags? | WSAPIRequestFlags |
Returns
Promise<TWSAPIResponse>
subscribe()
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
| Parameter | Type |
|---|---|
requests | | string | WsTopicRequest<string, any> | ( | string | WsTopicRequest<string, any>)[] |
wsKey | WsKey |
Returns
void
See
subscribeTopicsForWsKey()
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
| 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
| boolean | Promise<void> | Promise<WSConnectedResult | 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 |
|---|---|
wsKey | WsKey |
wsMessage | string |
throwExceptions? | boolean |
Returns
void
Inherited from
BaseWebsocketClient.tryWsSend
unsubscribe()
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
| Parameter | Type |
|---|---|
requests | | string | WsTopicRequest<string, any> | ( | string | WsTopicRequest<string, any>)[] |
wsKey | WsKey |
Returns
void