Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/coinbase-api/llms.txt
Use this file to discover all available pages before exploring further.
WebsocketClient is the unified WebSocket client for all Coinbase real-time feeds. It manages six simultaneous WebSocket connections across Advanced Trade, Exchange, International, and Prime — handling authentication, reconnection, and topic subscription automatically.
Installation & Setup
Constructor
WSClientConfigurableOptions
| Option | Type | Description |
|---|---|---|
apiKey | string | API key name (CDP key name for Advanced Trade / App; API key for Exchange, International, Prime). |
apiSecret | string | EC private key PEM string (Advanced Trade / App) or HMAC secret (Exchange, International, Prime). |
apiPassphrase | string | API passphrase. Required for Coinbase Exchange, International, and Prime WebSocket feeds. |
jwtExpiresSeconds | number | Seconds until the JWT expires for Advanced Trade auth. Defaults to 120. |
pingInterval | number | How often (ms) to send an upstream ping to keep the connection alive. Defaults to 10000. |
pongTimeout | number | How long (ms) to wait for a pong before treating the connection as dead. Defaults to 1000. |
reconnectTimeout | number | Delay (ms) before spawning a reconnection attempt. Defaults to 500. |
useSandbox | boolean | Connect to sandbox URLs where available (Exchange and International only). |
wsUrl | string | Override the WebSocket URL for all connections. |
wsOptions | object | Additional options passed directly to the underlying ws library (e.g. custom agent, protocols). |
customSignMessageFn | function | Provide your own HMAC-SHA256 signing implementation (e.g. Node.js createHmac for better performance). |
reauthWSAPIOnReconnect | boolean | Re-authenticate the WS API channel automatically on reconnect. Defaults to false. |
WS_KEY_MAP
Each of the six WebSocket connections is identified by aWsKey string constant from WS_KEY_MAP. Pass the appropriate key when calling subscribe, unsubscribe, or connect.
| Key | Value | URL (livenet) | Auth Required |
|---|---|---|---|
WS_KEY_MAP.advTradeMarketData | "advTradeMarketData" | wss://advanced-trade-ws.coinbase.com | — |
WS_KEY_MAP.advTradeUserData | "advTradeUserData" | wss://advanced-trade-ws-user.coinbase.com | 🔒 |
WS_KEY_MAP.exchangeMarketData | "exchangeMarketData" | wss://ws-feed.exchange.coinbase.com | — |
WS_KEY_MAP.exchangeDirectMarketData | "exchangeDirectMarketData" | wss://ws-direct.exchange.coinbase.com | 🔒 |
WS_KEY_MAP.internationalMarketData | "internationalMarketData" | wss://ws-md.international.coinbase.com | 🔒 |
WS_KEY_MAP.primeMarketData | "primeMarketData" | wss://ws-feed.prime.coinbase.com | 🔒 |
Sandbox WebSocket URLs are available for Exchange (
wss://ws-feed-public.sandbox.exchange.coinbase.com / wss://ws-direct.sandbox.exchange.coinbase.com) and International (wss://ws-md.n5e2.coinbase.com). Pass useSandbox: true to the constructor to use them automatically.Methods
connectAll()
Initiates connections for all six WebSocket feeds simultaneously. Returns a Promise that resolves with an array of WSConnectedResult | undefined — one entry per connection.
connectAll() explicitly — connections are established automatically on the first subscribe() call. Use connectAll() when you want to pre-establish all connections up front.
subscribe(requests, wsKey)
Subscribes to one or more topics on a specific WebSocket connection. Accepts a single topic, a WsTopicRequest object, or an array of either. Resubscription after a reconnect is automatic.
WsTopicRequest object — use this when the channel requires additional parameters like product_ids:
unsubscribe(requests, wsKey)
Removes subscription(s) from a WebSocket connection. Topics removed via unsubscribe are also removed from the reconnect cache and will not be re-subscribed after a reconnect.
sendWSAPIRequest(wsKey, channel, params?)
Sends a raw WebSocket API request. This is a low-level method; for most use cases, use subscribe / unsubscribe instead.
sendWSAPIRequest is defined in the base class but returns undefined for Coinbase WebSockets — the WS API pattern is not fully implemented for this exchange. Use subscribe for all subscription management.WsTopicRequest<T> Interface
WSConnectedResult Type
Returned by connectAll() and the underlying connect() method on a successful connection.
Events
WebsocketClient extends EventEmitter. Listen to events with .on(eventName, handler).
open
Emitted when a new WebSocket connection is opened for the first time.
reconnect
Emitted when a dropped connection is in the process of reconnecting.
reconnected
Emitted after a dropped connection has successfully reconnected. Topic re-subscription is automatic after this event.
close
Emitted when a WebSocket connection is closed.
response
Emitted in response to subscription/unsubscription requests (e.g. the subscriptions confirmation message from Advanced Trade). Use this to verify that a subscription succeeded.
update
The primary data event. Emitted for every incoming market data message. The wsKey field on the payload identifies which connection the message arrived on.