TheDocumentation 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 a single, unified client that manages every Coinbase WebSocket feed. You instantiate it once, attach event listeners, and call subscribe() — the client handles connection setup, authentication, heartbeats, and reconnection automatically.
How it works
Each distinct WebSocket server URL is represented internally as a WsKey — a short string constant defined inWS_KEY_MAP. When you call subscribe(topic, wsKey), the client looks up the right connection for that WsKey, opens it if it isn’t already open, authenticates if required, then sends the subscription request.
WS_KEY_MAP can be used as an enum to avoid typos. WS_KEY_MAP.advTradeMarketData and the plain string 'advTradeMarketData' are identical at runtime — use whichever you prefer.Available WsKeys
advTradeMarketData
Advanced Trade public market data — ticker, candles, order book, trades. No authentication required.
advTradeUserData
Advanced Trade private user data — order fills, futures balance. Authentication required.
exchangeMarketData
Coinbase Exchange public market data feed. No authentication required.
exchangeDirectMarketData
Coinbase Exchange direct feed with lower latency. Authentication always required.
internationalMarketData
Coinbase International (INTX) feed. Authentication always required.
primeMarketData
Coinbase Prime feed. Authentication always required.
Instantiation
- Public (no credentials)
- Private (Advanced Trade)
- Private (Exchange / International / Prime)
Subscribing to topics
Callsubscribe(topic | topics[], wsKey) to subscribe. Topics can be plain strings (no parameters needed) or structured objects with a payload for channels that require parameters such as product_ids.
Unsubscribing
unsubscribe() mirrors subscribe() exactly. The topic is removed from the SDK’s internal cache, so it won’t be resubscribed after a reconnect.
Event listeners
All data and lifecycle events are emitted on theWebsocketClient instance. Attach listeners before calling subscribe().
Event reference
| Event | Payload | When it fires |
|---|---|---|
open | { wsKey, event } | A new connection is established for the first time |
update | { wsKey, ...channelData } | The exchange sends channel data |
reconnect | { wsKey, event } | Connection dropped; client is attempting to reconnect |
reconnected | { wsKey, event } | Reconnection succeeded; topics are re-subscribed |
close | { wsKey, event } | Connection closed (expected or unexpected) |
response | { wsKey, ...reply } | Reply to a subscribe / unsubscribe / authenticate request |
exception | { wsKey, ...error } | An error occurred in the client or your listener |
Explicit connection
The client connects automatically the first time you callsubscribe(). To pre-open all connections at once (useful for minimising latency on the first message), call connectAll():
Auto-reconnect behaviour
If the underlying TCP connection drops, the client:- Emits a
reconnectevent. - Waits for
reconnectTimeoutmilliseconds (default500 ms). - Re-opens the connection and re-sends all active subscriptions.
- Emits a
reconnectedevent when complete.
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | API key name (Advanced Trade) or key ID |
apiSecret | string | — | EC private key (Advanced Trade) or HMAC secret |
apiPassphrase | string | — | Passphrase for Exchange / International / Prime |
pingInterval | number | 10000 | How often (ms) to send a ping |
pongTimeout | number | 1000 | How long (ms) to wait for a pong before assuming disconnect |
reconnectTimeout | number | 500 | Delay (ms) before attempting reconnect |
useSandbox | boolean | false | Connect to the sandbox (Exchange & International only) |
jwtExpiresSeconds | number | 120 | JWT TTL in seconds for Advanced Trade auth |