Designing and Implementing a Cryptocurrency Market Data System: From Market Snapshots to Real-Time Push
This article walks through the engineering behind a cryptocurrency market data system, starting from a single market snapshot. It covers the semantics and calculation logic of core fields (price, 24h change, market cap), data collection and cleansing from exchange APIs and WebSocket feeds, layered storage design with time-series K-line aggregation, a low-latency real-time push pipeline, frontend rendering considerations, and stability practices such as end-to-end latency monitoring, data reconciliation, and graceful degradation. Readers will learn how to build a reliable, high-quality market data foundation for trading terminals, dashboards, and quantitative backtesting scenarios.
1. Starting from a Market Snapshot
In the cryptocurrency domain, the market state of any trading pair can be condensed into a single structured snapshot. Take a USDT trading pair as an example — its snapshot looks roughly like this (values are illustrative):
{"symbol": "XXXUSDT","market_type": "CRYPTO","last_price": 0.09109,"currency": "USD","change_24h": 0.002397,"change_pct_24h": 2.703,"open_24h": 0.0887,"high_24h": 0.09369,"low_24h": 0.0876,"market_cap": 91616500,"market_cap_rank": 166,"updated_at": "2026-11-24 14:42:38"}
This snapshot looks simple, but behind it lies a full set of engineering problems in a market data system: where the data comes from, how it is validated, how it is stored, how it is pushed, and how it is displayed. This article walks through that pipeline layer by layer.
2. Core Field Semantics and Calculation Logic
2.1 Price Fields
- last_price: the latest traded price, usually taken from the most recent trade or the best price in the order book.
- open_24h: the price 24 hours ago, used as the baseline for change calculations.
- high_24h / low_24h: the extremes within a rolling 24-hour window, which requires sliding-window statistics.
The change is calculated as:
change_pct = (last_price - open_24h) / open_24h * 100change_abs = last_price - open_24h
Note: different platforms may define the “24-hour” window differently — some use a rolling window, others use a calendar-day cutoff. You must align these definitions before reconciling data across sources.
2.2 Market Cap Fields
Market cap = circulating supply × latest price. Market cap rank is the position of the asset when the entire market is sorted by market cap. This is a global aggregate metric, typically computed periodically by a separate service rather than in real time within the market data push pipeline.
3. Data Collection and Cleansing
Market data typically comes from three types of sources: polling public exchange APIs, WebSocket feeds, and aggregated data services. In engineering practice, pay attention to the following:
- Timestamp alignment: different sources have different timestamp precision and time zones. Normalize everything to UTC milliseconds before persistence.
- Deduplication: WebSocket reconnects can cause duplicate pushes. Ensure idempotency based on
(symbol, event_id). - Outlier filtering: data with a price of zero, negative values, or an instantaneous deviation beyond a threshold should be discarded and trigger an alert.
Illustrative cleansing logic:
def clean(tick):if tick["last_price"] <= 0:return Noneif abs(tick["last_price"] - tick["prev_price"]) / tick["prev_price"] > 0.5:alert(tick) # abnormal movement, manual review requiredreturn Nonetick["ts"] = to_utc_ms(tick["updated_at"])return tick
4. Storage Design
A market data system usually adopts layered storage:
- Hot data layer: an in-memory database or cache holding only the latest snapshots, supporting high-concurrency reads.
- K-line (candlestick) layer: a time-series database storing candles at multiple granularities (1m/5m/1h/1d), with window aggregation performed at write time.
- Historical archive layer: object storage with a columnar format, used for backtesting and research.
The key point of K-line aggregation is window boundary handling. Taking 1-minute candles as an example:
bucket = ts // 60000 * 60000# within the same bucket: open = first tick, close = last tick,# high = max, low = min, volume = sum
5. Real-Time Push Pipeline
Market display is latency-sensitive. The recommended architecture is: data source → message queue → aggregation service → push gateway → frontend. Key considerations:
- Load leveling: during market surges (e.g., sharp price swings), message volume spikes. A message queue buffers the traffic so downstream services are not overwhelmed.
- Batched pushing: multiple updates for the same trading pair can be merged within a 50–200 ms window before pushing, significantly reducing bandwidth and frontend rendering pressure.
- Reconnection recovery: after a client reconnects, it should first fetch a full snapshot and then resume incremental pushes, avoiding inconsistent state.
Push messages should be as compact as possible — for example, sending only changed fields or using an incremental diff format.
6. Frontend Display Considerations
- Use number-rolling animations and thousands separators; distinguish gains and losses with red/green coloring.
- Stale data indicator: if
updated_atis older than a configured threshold, show a “data delayed” marker. - Debounced rendering: under high-frequency pushes, merge render frames with
requestAnimationFrameto avoid page jank.
7. Stability and Monitoring
- Pipeline latency monitoring: track end-to-end latency from the data source timestamp to client-side display, and include the P99 metric in alerting.
- Data consistency reconciliation: periodically compare snapshots between the market data service and the source to detect missing or incorrect data early.
- Degradation strategy: when the push pipeline fails, automatically fall back to HTTP polling to maintain basic availability.
8. Conclusion
A single market snapshot is a microcosm of the entire cryptocurrency market data system. Building a reliable system comes down to: unified data definitions, proper cleansing and idempotency, layered storage, batched pushing, and thorough monitoring and reconciliation. Mastering this pipeline enables you to build high-quality foundational data capabilities for trading terminals, data dashboards, and quantitative backtesting alike.
