Order Book
Prime aggregates liquidity from multiple venues into a single, unified order book for each trading pair. This consolidated view provides clients with access to the best available prices and deeper liquidity than any individual venue could offer alone. The aggregated order book represents the current state of all listed buy and sell orders. This unified liquidity pool enables more efficient price discovery and better execution for all order types.Crossed Bids and Asks
Prime’s multi-venue liquidity aggregation may result in crossed bids and asks where the highest bid price exceeds the lowest ask price. Do not filter out crossed markets - they represent real liquidity available for execution and are an expected characteristic of aggregated order books. Prime’s execution engine handles these conditions appropriately during order processing.Real-time Order Book Updates
Prime provides a WebSocket feed that can be used to maintain a real-time copy of the order book. Thel2_data
provides both an initial snapshot and real-time updates, enabling you to maintain an accurate local representation of the order book state. This is essential for Crypto-as-a-Service (CaaS) applications requiring real-time pricing information.
Sequence Number Tracking: Each l2_data
message contains a monotonically increasing sequence number. You must track these sequence numbers to ensure no updates are missed. If you detect a gap in sequence numbers, immediately disconnect and reconnect to request a fresh snapshot.
Heartbeat Monitoring: Implement a heartbeats
channel subscription in parallel with l2_data
to monitor connection health. If heartbeats stop arriving, treat this as a connection issue and reconnect.
Update Processing: No delta math is required when processing updates. Simply replace the existing px
level with the updated qty
at that level. If you receive a quantity of 0
for a price level, this indicates there is no more liquidity at that price level - remove it from your local order book until you receive the next update at that price.
Disclaimer: The following examples are provided for reference purposes only.Copyright 2025 Coinbase Global, Inc.Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Example: Maintaining Best Bid and Ask
The following Java example demonstrates how to connect to the Prime WebSocket feed and maintain real-time best bid and best ask prices:Candles Data
Prime provides historical OHLCV (Open, High, Low, Close, Volume) candle data via REST API. This endpoint is currently in early access but will roll out to full general access soon. This data is returned as an array based on two epoch timestamps, with support for up to 350 candles per request. You can specify granularity to establish the bin size, ranging fromONE_MINUTE
to ONE_DAY
.
Candles data is especially useful for:
- Creating price charts and technical analysis
- Calculating price changes over time periods
- Building trading algorithms based on historical patterns