- Market Data is our traditional feed that provides updates for both orders and trades. Most channels are now available without authentication.
- User Order Data provides updates for the orders of the user.
Market Data Endpoint:
User Order Data Endpoint:
wss://advanced-trade-ws.coinbase.com
User Order Data Endpoint:
wss://advanced-trade-ws-user.coinbase.com
You can subscribe to the Heartbeats Channel, User Channel and Futures Balance Summary Channel with the User Order Data endpoint. If advanced-trade-ws-user is your primary connection, we recommend using advanced-trade-ws as a failover.
Protocol
The WebSocket feed uses a bidirectional protocol that encodes all messages as JSON objects. All messages have atype
attribute that can be used to handle the message appropriately.
New message types can be added at any time. Clients are expected to ignore messages they do not support.
Sending Messages with CDP Keys
Subscribing
To begin receiving feed messages, you must send asubscribe
message to the server indicating which channel and products to receive. This message is mandatory and you are disconnected if no subscribe
has been received within 5 seconds.
You can subscribe to multiple channels but you must send a unique subscription message for each channel.
To receive feed messages, you must send a
subscribe
message or you are disconnected in 5 seconds.channel
name and jwt
:
-
channel
name as a string. You can only subscribe to one channel per subscription message. -
jwt
can be generated by running one of the code snippets provided in the WebSocket Authentication page. Remember that you must generate a different JWT for each websocket message sent, since the JWTs will expire after 2 minutes.
Unsubscribing
To unsubscribe from a channel/product pair, send anunsubscribe
message. The structure is the same as subscribe
message. You can only unsubscribe from one channel per subscription message. You can also unsubscribe from a channel entirely by providing no product IDs.
subscriptions
message as a response to an unsubscribe
message.
Websocket Code Samples
Use the code samples to subscribe to one or more Advanced Trade WebSocket channels using CDP API Keys.Sending Messages without API Keys
Subscribing
Unsubscribing
Sequence Numbers
Most feed messages contain a sequence number. Sequence numbers are increasing integer values for each product, with each new message being exactly one sequence number greater than the one before it. Sequence numbers that are greater than one integer value from the previous number indicate that a message has been dropped. Sequence numbers that are less than the previous number can be ignored or represent a message that has arrived out of order. In either situation you may need to perform logic to make sure your system is in the correct state.Even though a WebSocket connection is over TCP, the WebSocket servers receive market data in a manner that can result in dropped messages. Your feed consumer should be designed to handle sequence gaps and out of order messages, or should use channels that guarantee delivery of messages.
To guarantee that messages are delivered and your order book is in sync, consider using the level2 channel.