Skip to content

Class: WebsocketClientV1 ​

Deprecated ​

This legacy websocket client creates one websocket connection per topic.

If subscribing to a lot of topics, consider using the new multiplex WebsocketClient.

To split your topics into smaller groups (one connection per group), simply make multiple multiplex WebsocketClient instances.

Extends ​

  • EventEmitter

Constructors ​

Constructor ​

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

Parameters ​

ParameterTypeDescription
optionsWSClientConfigurableOptions-
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) => voidPing/pong events and other raw messages that might be noisy. Enable this while troubleshooting.

Returns ​

WebsocketClientV1

Methods ​

close() ​

ts
close(wsKey: string, shouldReconnectAfterClose?: boolean): void;

Parameters ​

ParameterType
wsKeystring
shouldReconnectAfterClose?boolean

Returns ​

void


closeAll() ​

ts
closeAll(shouldReconnectAfterClose?: boolean): void;

Parameters ​

ParameterType
shouldReconnectAfterClose?boolean

Returns ​

void


closeWs() ​

ts
closeWs(ws: WebSocket, shouldReconnectAfterClose?: boolean): void;

Parameters ​

ParameterType
wsWebSocket
shouldReconnectAfterClose?boolean

Returns ​

void


connectToWsUrl() ​

ts
connectToWsUrl(
   url: string, 
   wsKey?: string, 
   forceNewConnection?: boolean
): WebSocket;

Parameters ​

ParameterType
urlstring
wsKey?string
forceNewConnection?boolean

Returns ​

WebSocket


getWs() ​

ts
getWs(wsKey: string): WebSocket | undefined;

Parameters ​

ParameterType
wsKeystring

Returns ​

WebSocket | undefined


on() ​

Call Signature ​

ts
on(event: "reply", listener: (event: WsResponse) => void): this;
Parameters ​
ParameterType
event"reply"
listener(event: WsResponse) => void
Returns ​

this

Call Signature ​

ts
on(event: "message", listener: (event: WsRawMessage) => void): this;
Parameters ​
ParameterType
event"message"
listener(event: WsRawMessage) => void
Returns ​

this

Call Signature ​

ts
on(event: "formattedMessage", listener: (event: WsFormattedMessage) => void): this;
Parameters ​
ParameterType
event"formattedMessage"
listener(event: WsFormattedMessage) => void
Returns ​

this

Call Signature ​

ts
on(event: "formattedUserDataMessage", listener: (event: WsUserDataEvents) => void): this;
Parameters ​
ParameterType
event"formattedUserDataMessage"
listener(event: WsUserDataEvents) => void
Returns ​

this

Call Signature ​

ts
on(event: "error", listener: (event: object) => void): this;
Parameters ​
ParameterType
event"error"
listener(event: object) => void
Returns ​

this

Call Signature ​

ts
on(event: "open" | "reconnected", listener: (event: object) => void): this;
Parameters ​
ParameterType
event"open" | "reconnected"
listener(event: object) => void
Returns ​

this

Call Signature ​

ts
on(event: "close" | "reconnecting", listener: (event: object) => void): this;
Parameters ​
ParameterType
event"close" | "reconnecting"
listener(event: object) => void
Returns ​

this


requestGetProperty() ​

ts
requestGetProperty(
   wsKey: WsKey, 
   property: string, 
   requestId: number
): void;

Send WS message to get property state

Parameters ​

ParameterType
wsKeyWsKey
propertystring
requestIdnumber

Returns ​

void


requestListSubscriptions() ​

ts
requestListSubscriptions(wsKey: WsKey, requestId: number): void;

Send WS message to unsubscribe from topics.

Parameters ​

ParameterType
wsKeyWsKey
requestIdnumber

Returns ​

void


requestSetProperty() ​

ts
requestSetProperty(
   wsKey: WsKey, 
   property: string, 
   value: any, 
   requestId: number
): void;

Send WS message to set property state

Parameters ​

ParameterType
wsKeyWsKey
propertystring
valueany
requestIdnumber

Returns ​

void


subscribeAggregateTrades() ​

ts
subscribeAggregateTrades(
   symbol: string, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to aggregate trades for a symbol in a market category

Parameters ​

ParameterType
symbolstring
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeAll24hrTickers() ​

ts
subscribeAll24hrTickers(market: "spot" | "usdm" | "coinm", forceNewConnection?: boolean): WebSocket;

Subscribe to 24hr ticker in any market.

Parameters ​

ParameterType
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeAllBookTickers() ​

ts
subscribeAllBookTickers(market: "spot" | "usdm" | "coinm", forceNewConnection?: boolean): WebSocket;

Subscribe to best bid/ask for all symbols in spot markets.

Parameters ​

ParameterType
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeAllLiquidationOrders() ​

ts
subscribeAllLiquidationOrders(market: "usdm" | "coinm", forceNewConnection?: boolean): WebSocket;

Subscribe to best bid/ask for all symbols in spot markets.

Parameters ​

ParameterType
market"usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeAllMarketMarkPrice() ​

ts
subscribeAllMarketMarkPrice(
   market: "usdm" | "coinm", 
   updateSpeedMs?: 1000 | 3000, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to mark price for all symbols in a market category

Parameters ​

ParameterTypeDefault value
market"usdm" | "coinm"undefined
updateSpeedMs?1000 | 30003000
forceNewConnection?booleanundefined

Returns ​

WebSocket


subscribeAllMini24hrTickers() ​

ts
subscribeAllMini24hrTickers(market: "spot" | "usdm" | "coinm", forceNewConnection?: boolean): WebSocket;

Subscribe to mini 24hr mini ticker in market category.

Parameters ​

ParameterType
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeAllRollingWindowTickers() ​

ts
subscribeAllRollingWindowTickers(
   market: "spot", 
   windowSize: "1h" | "4h" | "1d", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to rolling window ticker statistics for all market symbols, computed over multiple windows. Note that only tickers that have changed will be present in the array.

Notes:

  • Supported window sizes: 1h,4h,1d.
  • Supported markets: spot

Parameters ​

ParameterType
market"spot"
windowSize"1h" | "4h" | "1d"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeBlockTrades() ​

ts
subscribeBlockTrades(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to block trades for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeCoinFuturesUserDataStream() ​

ts
subscribeCoinFuturesUserDataStream(
   isTestnet?: boolean, 
   forceNewConnection?: boolean, 
   isReconnecting?: boolean
): Promise<WebSocket | undefined>;

Subscribe to COIN-M Futures user data stream - listen key is automatically generated.

Parameters ​

ParameterType
isTestnet?boolean
forceNewConnection?boolean
isReconnecting?boolean

Returns ​

Promise<WebSocket | undefined>


subscribeCoinIndexPrice() ​

ts
subscribeCoinIndexPrice(
   symbol: string, 
   _updateSpeedMs?: 1000 | 3000, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to coin index for a symbol in COINM Futures markets _updateSpeedMs is ignored (<pair>@indexPrice@1s was removed). Drop this arg in the next major.

Parameters ​

ParameterTypeDefault value
symbolstringundefined
_updateSpeedMs?1000 | 30003000
forceNewConnection?booleanundefined

Returns ​

WebSocket


subscribeContinuousContractKlines() ​

ts
subscribeContinuousContractKlines(
   symbol: string, 
   contractType: "perpetual" | "current_quarter" | "next_quarter", 
   interval: KlineInterval, 
   market: "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to continuous contract klines(candles) for a symbol futures

Parameters ​

ParameterType
symbolstring
contractType"perpetual" | "current_quarter" | "next_quarter"
intervalKlineInterval
market"usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeContractInfoStream() ​

ts
subscribeContractInfoStream(market: "usdm" | "coinm", forceNewConnection?: boolean): WebSocket;

Subscribe to best bid/ask for all symbols in spot markets.

Parameters ​

ParameterType
market"usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeDiffBookDepth() ​

ts
subscribeDiffBookDepth(
   symbol: string, 
   updateMs?: 100 | 250 | 500 | 1000, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to orderbook depth updates to locally manage an order book.

Note that the updatems parameter depends on which market you're trading

Use getContextFromWsKey(data.wsKey) to extract symbol from events

Parameters ​

ParameterTypeDefault value
symbolstringundefined
updateMs?100 | 250 | 500 | 1000100
market"spot" | "usdm" | "coinm"undefined
forceNewConnection?booleanundefined

Returns ​

WebSocket


subscribeEndpoint() ​

ts
subscribeEndpoint(
   endpoint: string, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to a universal market websocket stream

Parameters ​

ParameterType
endpointstring
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeIndexKlines() ​

ts
subscribeIndexKlines(
   symbol: string, 
   interval: KlineInterval, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to index klines(candles) for a symbol in a coinm futures

Parameters ​

ParameterType
symbolstring
intervalKlineInterval
forceNewConnection?boolean

Returns ​

WebSocket


subscribeIsolatedMarginUserDataStream() ​

ts
subscribeIsolatedMarginUserDataStream(
   symbol: string, 
   forceNewConnection?: boolean, 
   isReconnecting?: boolean
): Promise<WebSocket | undefined>;

Subscribe to isolated margin user data stream - listen key is automatically generated.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean
isReconnecting?boolean

Returns ​

Promise<WebSocket | undefined>


subscribeKlines() ​

ts
subscribeKlines(
   symbol: string, 
   interval: KlineInterval, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to klines(candles) for a symbol in a market category

Parameters ​

ParameterType
symbolstring
intervalKlineInterval
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeMarginUserDataStream() ​

ts
subscribeMarginUserDataStream(forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket | undefined>;

Subscribe to margin user data stream - listen key is automatically generated.

Parameters ​

ParameterType
forceNewConnection?boolean
isReconnecting?boolean

Returns ​

Promise<WebSocket | undefined>


subscribeMarkPrice() ​

ts
subscribeMarkPrice(
   symbol: string, 
   market: "usdm" | "coinm", 
   updateSpeedMs?: 1000 | 3000, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to mark price for a symbol in a market category

Parameters ​

ParameterTypeDefault value
symbolstringundefined
market"usdm" | "coinm"undefined
updateSpeedMs?1000 | 30003000
forceNewConnection?booleanundefined

Returns ​

WebSocket


subscribeMarkPriceKlines() ​

ts
subscribeMarkPriceKlines(
   symbol: string, 
   interval: KlineInterval, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to index klines(candles) for a symbol in a coinm futures

Parameters ​

ParameterType
symbolstring
intervalKlineInterval
forceNewConnection?boolean

Returns ​

WebSocket


subscribePartialBookDepths() ​

ts
subscribePartialBookDepths(
   symbol: string, 
   levels: 5 | 10 | 20, 
   updateMs: 100 | 250 | 500 | 1000, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to partial book depths (snapshots).

Note:

  • spot only supports 1000ms or 100ms for updateMs
  • futures only support 100, 250 or 500ms for updateMs

Use getContextFromWsKey(data.wsKey) to extract symbol from events

Parameters ​

ParameterType
symbolstring
levels5 | 10 | 20
updateMs100 | 250 | 500 | 1000
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotAggregateTrades() ​

ts
subscribeSpotAggregateTrades(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to aggregate trades for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotAll24hrTickers() ​

ts
subscribeSpotAll24hrTickers(forceNewConnection?: boolean): WebSocket;

Subscribe to 24hr ticker in spot markets.

Parameters ​

ParameterType
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotAllBookTickers() ​

ts
subscribeSpotAllBookTickers(forceNewConnection?: boolean): WebSocket;

Subscribe to best bid/ask for all symbols in spot markets.

Parameters ​

ParameterType
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotAllMini24hrTickers() ​

ts
subscribeSpotAllMini24hrTickers(forceNewConnection?: boolean): WebSocket;

Subscribe to mini 24hr mini ticker in spot markets.

Parameters ​

ParameterType
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotBlockTrades() ​

ts
subscribeSpotBlockTrades(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to block trades for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotDiffBookDepth() ​

ts
subscribeSpotDiffBookDepth(
   symbol: string, 
   updateMs?: 100 | 1000, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to spot orderbook depth updates to locally manage an order book.

Parameters ​

ParameterTypeDefault value
symbolstringundefined
updateMs?100 | 10001000
forceNewConnection?booleanundefined

Returns ​

WebSocket


subscribeSpotKline() ​

ts
subscribeSpotKline(
   symbol: string, 
   interval: KlineInterval, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to candles for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
intervalKlineInterval
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotPartialBookDepth() ​

ts
subscribeSpotPartialBookDepth(
   symbol: string, 
   levels: 5 | 10 | 20, 
   updateMs?: 100 | 1000, 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to top bid/ask levels for symbol in spot markets.

Parameters ​

ParameterTypeDefault value
symbolstringundefined
levels5 | 10 | 20undefined
updateMs?100 | 10001000
forceNewConnection?booleanundefined

Returns ​

WebSocket


subscribeSpotSymbol24hrTicker() ​

ts
subscribeSpotSymbol24hrTicker(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to 24hr ticker for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotSymbolBookTicker() ​

ts
subscribeSpotSymbolBookTicker(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to best bid/ask for symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotSymbolMini24hrTicker() ​

ts
subscribeSpotSymbolMini24hrTicker(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to mini 24hr ticker for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotTrades() ​

ts
subscribeSpotTrades(symbol: string, forceNewConnection?: boolean): WebSocket;

Subscribe to trades for a symbol in spot markets.

Parameters ​

ParameterType
symbolstring
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSpotUserDataStream() ​

ts
subscribeSpotUserDataStream(forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket | undefined>;

Subscribe to spot user data stream - listen key is automaticallyr generated. Calling multiple times only opens one connection.

Parameters ​

ParameterType
forceNewConnection?boolean
isReconnecting?boolean

Returns ​

Promise<WebSocket | undefined>


subscribeSpotUserDataStreamWithListenKey() ​

ts
subscribeSpotUserDataStreamWithListenKey(
   listenKey: string, 
   forceNewConnection?: boolean, 
   isReconnecting?: boolean
): WebSocket | undefined;

Subscribe to a spot user data stream. Use REST client to generate and persist listen key. Supports spot, margin & isolated margin listen keys.

Parameters ​

ParameterType
listenKeystring
forceNewConnection?boolean
isReconnecting?boolean

Returns ​

WebSocket | undefined


subscribeSymbol24hrTicker() ​

ts
subscribeSymbol24hrTicker(
   symbol: string, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to 24hr ticker for a symbol in any market.

Parameters ​

ParameterType
symbolstring
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSymbolBookTicker() ​

ts
subscribeSymbolBookTicker(
   symbol: string, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to best bid/ask for symbol in spot markets.

Parameters ​

ParameterType
symbolstring
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSymbolLiquidationOrders() ​

ts
subscribeSymbolLiquidationOrders(
   symbol: string, 
   market: "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to best bid/ask for symbol in spot markets.

Parameters ​

ParameterType
symbolstring
market"usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeSymbolMini24hrTicker() ​

ts
subscribeSymbolMini24hrTicker(
   symbol: string, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to mini 24hr ticker for a symbol in market category.

Parameters ​

ParameterType
symbolstring
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeTrades() ​

ts
subscribeTrades(
   symbol: string, 
   market: "spot" | "usdm" | "coinm", 
   forceNewConnection?: boolean
): WebSocket;

Subscribe to trades for a symbol in a market category IMPORTANT: This topic for usdm and coinm is not listed in the api docs and might stop working without warning

Parameters ​

ParameterType
symbolstring
market"spot" | "usdm" | "coinm"
forceNewConnection?boolean

Returns ​

WebSocket


subscribeUsdFuturesUserDataStream() ​

ts
subscribeUsdFuturesUserDataStream(
   isTestnet?: boolean, 
   forceNewConnection?: boolean, 
   isReconnecting?: boolean
): Promise<WebSocket | undefined>;

Subscribe to USD-M Futures user data stream - listen key is automatically generated.

Parameters ​

ParameterType
isTestnet?boolean
forceNewConnection?boolean
isReconnecting?boolean

Returns ​

Promise<WebSocket | undefined>


tryWsPing() ​

ts
tryWsPing(wsKey: string): void;

Parameters ​

ParameterType
wsKeystring

Returns ​

void


tryWsSend() ​

ts
tryWsSend(wsKey: string, wsMessage: string): void;

Parameters ​

ParameterType
wsKeystring
wsMessagestring

Returns ​

void

Built by Siebly. Open source SDKs for exchange APIs.