Working with websockets
- Keep subscriptions open with heartbeats. Most channels close within 60-90 seconds when no updates are sent. Subscribe to the heartbeats channel alongside your other channels to keep all subscriptions open — especially useful for illiquid pairs.
- Authenticate for a reliable connection. For the most reliable connection, authenticate with a CDP API key when subscribing to any channel.
- USDC products. Subscribing to
-USDCproducts is only available on the user channel. Other channels return the same data as the corresponding-USDproducts.USDT-USDCandEURC-USDCare available on all channels.
- Subscribing to a WebSocket channel
- Advanced Trade API reference for the full WebSocket specs
Heartbeats Channel
Subscribe to theheartbeats channel to receive heartbeats messages every second. Heartbeats include a heartbeat_counter which verifies that no messages were missed.
heartbeats as seen below.
Candles Channel
Subscribe to thecandles channel to receive candles messages for specific products with updates every second. Candles are grouped into buckets (granularities) of five minutes.
candles and some of its parameters include:
start- string representation of the UNIX timestamp of the candle.highandlow- highest and lowest prices during the bucket interval.openandclose- prices of the first and last trade respectively.volume- base amount that has been traded during this interval.product_id- product identifier for this candle
Market Trades Channel
Themarket_trades channel sends market trades for a specified product on a preset interval. Clients should provide an array of product_ids for which they would like status subscriptions.
snapshot or update, and contains an array of market trades. Each market trade belongs to a side, which refers to the makers side, and can be of type BUY, or SELL. The channel collects all updates over the last 250 ms and sends them as an update — so an update can contain one or many trades, depending on the last 250 ms of trading volume.
Status Channel
Thestatus channel sends all products and currencies on a preset interval. Clients should provide an array of product_ids for which they would like status subscriptions.
Ticker Channel
Theticker channel provides real-time price updates every time a match happens. It batches updates in case of cascading matches, greatly reducing bandwidth requirements.
Ticker Batch Channel
Theticker_batch channel provides latest price updates every 5000 milliseconds (5 seconds) if there is a change. It has the same JSON message schema as the ticker channel, except the channel field will have a value of ticker_batch and it currently doesn’t provide best bid or best ask fields.
Level2 Channel
Thelevel2 channel guarantees delivery of all updates and is the easiest way to keep a snapshot of the order book.
type (“snapshot” or “update”), product_id, and updates. The field updates is an array of objects of {price_level, new_quantity, event_time, side} to represent the entire order book. Theevent_time property is the time of the event as recorded by our trading engine.
The
new_quantity property is the updated size at that price level, not a delta. A new_quantity of “0” indicates the price level can be removed.User Channel
Theuser channel sends updates on all of a user’s open orders and current positions, including all subsequent updates of those orders and positions.
The user channel expects one connection per user:
- This connection accepts multiple product IDs in a
product_idsarray. If none are provided, the WebSocket subscription is open to all product IDs. - To subscribe to new
product_ids, close your previous connection by unsubscribing and open a new connection withproduct_idsadded to the array.
Orders Fields
Positions Fields
Numeric values are in units of USDC.The
positions fields are in beta and is currently returned as an empty array by default. To enable access to the positions fields in the User WebSocket channel, please reach out to us through Discord.Perpetual Futures
Expiring Futures
The
positions object also includes a prediction_market_positions array. This field is in beta.Futures Balance Summary Channel
Thefutures_balance_summary channel sends updates on all of a user’s futures balances, including all subsequent updates of those balances.
See Also: