Market Data Pipeline for Digital Assets: Collection, Validation, and Real-Time Display
This article walks through a practical market data pipeline for digital assets, built from a single price snapshot. It explains a three-layer data model (identity, price, and derived metrics), why price fields require fixed-point or string handling instead of floating point, and how to enforce UTC timestamps with monotonicity checks. It then covers multi-source collection with majority-and-freshness selection, four validation dimensions, a snapshot-plus-incremental push strategy for low-latency display, and the observability metrics and capacity planning needed to run the service reliably. The approach is vendor-neutral and can be assembled on general-purpose cloud capabilities such as message queues, container platforms, object storage, logging, and alerting.
1. Start With the Data Structure Behind a Market Snapshot
The source material is a market data record for a digital asset at a single point in time. It includes fields such as trading identifier, trading pair, market type, asset name, latest traded price, quote currency, 24-hour change amount and percentage, open, high, low, market cap, market cap rank, and data update time. These fields look simple, but engineering them carelessly leads to inconsistent definitions, precision loss, and out-of-order timestamps.
A practical approach is to model market data in three layers:
{"symbol": "GLM","pair": "GLMUSDT","market": "CRYPTO","quote_currency": "USD","price": 0.09119,"change_24h": 0.002497,"change_pct_24h": 2.815,"open_24h": 0.0887,"high_24h": 0.09369,"low_24h": 0.0876,"market_cap": 91616500,"rank": 166,"ts": "2026-11-24T14:39:36Z"}
The first layer is the identity layer, which uniquely identifies a trading instrument. The second is the price layer, which carries the latest price and 24-hour statistics. The third is the derived layer, which holds aggregate metrics such as market cap and rank. Layering decouples fields that refresh at different rates: the price layer updates at high frequency, while the derived layer is recomputed less often.
2. Precision and Timestamps: Two Commonly Overlooked Pitfalls
Price fields must be stored as fixed-point values or strings, never written to storage directly as floating point. A decimal like 0.09119 produces a tail error under binary floating point, and that error is amplified once values are accumulated. Two common approaches exist: store integers in the smallest quote unit and convert only for display, or use a high-precision decimal type and preserve the original string during serialization.
Timestamps must be normalized to a timezone-aware UTC representation, with the interface layer rendering them in the user’s timezone. Every “24-hour” statistic in a market data system depends on a continuous time series with no gaps; once the time baseline drifts, change percentages and high/low values become inaccurate. A forced check at the data entry point is therefore recommended: timestamps must increase monotonically, and writes should be rejected with an alert when the deviation from the local clock exceeds a threshold.
from decimal import Decimaldef normalize(raw: dict) -> dict:price = Decimal(str(raw["price"]))open_ = Decimal(str(raw["open_24h"]))change = price - open_pct = (change / open_ * 100).quantize(Decimal("0.001"))assert Decimal(str(raw["high_24h"])) >= price >= Decimal(str(raw["low_24h"]))return {**raw, "change_24h": change, "change_pct_24h": pct}
This sample code reflects two principles: all computation happens in the decimal domain, and a range consistency assertion runs before the write, ensuring the high is not below the latest price and the latest price is not below the low.
3. Multi-Source Collection and Consistency Checks
A single data source cannot guarantee availability. The established practice is to connect multiple market data sources in parallel and select the primary value using a “majority agreement plus most recent” strategy. The flow is as follows: data from each source first enters a message queue buffer, a unified validation service performs deduplication and alignment, and a snapshot is generated using the latest timestamp as the baseline. If the price difference between two sources exceeds a configured threshold, the value is flagged as anomalous, display is degraded, and an alert is triggered.
Validation should cover four dimensions: field completeness, numeric range, timestamp freshness, and cross-source deviation. A failure on any dimension should not be allowed to contaminate the main pipeline; instead, the record goes to an isolation queue for manual or rule-based review.
4. Engineering Tradeoffs for Real-Time Push and Display
Market data display is latency-sensitive, but not every field needs to travel over a high-frequency channel. A “snapshot plus incremental” model works well: the initial connection delivers a full snapshot, and only changed fields are pushed afterward, with the client merging them locally. For the transport layer, prefer a persistent connection with heartbeat and reconnect handling; for low-frequency metrics such as rank and market cap, extend cache time to reduce backend load.
On the visualization side, show both absolute and percentage change, and use color and arrows as redundant encoding so the information does not become unreadable when color alone is relied upon. All displayed values should follow a uniform decimal-place rule to prevent a mix of 0.0912 and 0.09119 on the same page.
5. Observability and Capacity Planning
A market data service must ship with monitoring: collection latency, validation failure rate, push success rate, connection count, and cache hit rate form the core metrics dashboard. The logging service retains anomalous samples, and monitoring alerts notify on-call staff when thresholds are breached. For capacity planning, estimate connections and bandwidth from peak subscription counts and reserve headroom for burst traffic; stateless compute and push nodes can scale elastically on a container platform, while raw market data samples are archived long-term in object storage for replay and retrospective analysis.
6. Summary
Breaking an ordinary-looking market snapshot into a three-layer model of identity, price, and derived metrics, then layering on precision handling, timestamp unification, multi-source validation, incremental push, and observability, yields a reusable market data pipeline. The design is vendor-neutral: developers can assemble it on general-purpose capabilities such as the message queue, container platform, object storage, logging service, and monitoring and alerting offered by Baidu AI Cloud, producing a stable, accurate, and scalable market data display system.
