WebsocketClient extends Node.js EventEmitter. All activity — incoming data, connection lifecycle, and errors — is surfaced through named events. Attach listeners with .on() before calling subscribe().
Event summary
| Event | When it fires |
|---|---|
update | A subscribed channel pushes new data |
response | A subscribe, unsubscribe, or auth confirmation is received |
open | A WebSocket connection is opened |
reconnect | A reconnection attempt is about to begin |
reconnected | A reconnection attempt succeeded |
exception | An error message is received or authentication fails |
authenticated | Authentication on a private connection succeeded |
update
Fires for every incoming data message from a subscribed channel.
arg.channel— the channel name that produced this update (e.g.'tickers','trades','account').data— the array of records in this update, shaped according to the channel.wsKey— identifies the underlying connection (e.g.'prodPublic','prodPrivate').
response
Fires when the server acknowledges a subscribe, unsubscribe, or login request. Also fires for WS API operation results.
open
Fires each time a WebSocket connection is first established (including after reconnections).
reconnect
Fires when the client detects a dropped connection and is about to attempt reconnection. The connection is not yet restored at this point.
reconnected
Fires after a reconnection attempt succeeds and the connection is re-established. At this point the client has also re-authenticated (if required) and resubscribed all active topics.
exception
Fires when an error message is received from the server, when authentication fails, or when a WS API operation returns a non-zero error code.
| Code | Meaning |
|---|---|
60005 | Invalid API key |
60009 | Login failed |
60011 | Already authenticated |
authenticated
Fires after a private connection successfully authenticates. Useful for performing actions that depend on auth being complete.
TypeScript types
The full set of event types is expressed viaWSClientEventMap:
WebsocketClient.on() method is fully typed. TypeScript will infer the correct payload shape based on the event name:
Complete handler example
This is the canonical event listener setup from the public channel example:Best practices
- Register all listeners before subscribing. Subscribing may open the connection immediately, and events can arrive before you attach handlers.
- Route in
updatebydata.arg.channel. A single client can hold many subscriptions; switching on the channel name keeps your handler readable. - Always handle
exception. Unhandled exceptions are logged but not thrown. Ignoring auth errors will result in a reconnect loop with invalid credentials. - Use
responsefor confirmation, notupdate. Theresponseevent confirms that a subscription or auth request was accepted. Channel data only flows onupdate. - Use
reconnectedto verify state. After a reconnection all subscriptions are automatically restored, but if your application maintains derived state (e.g. an in-memory order book) you may need to reset it using the snapshot that arrives after resubscription.

