Market Data Pipeline for Digital Assets: Collection, Validation, and Real-Time Display
This article walks through a practical approach to building a digital asset market data system, using a sample ticker snapshot to explain how to model raw exchange payloads into stable internal structures. It covers three layers of data validation (structural, business consistency, and time-series), how to decouple collection from business logic with a message queue, how to push incremental updates to the frontend with throttled rendering, and which observability metrics and common pitfalls to watch for. Readers will get concrete data modeling, validation, and architecture guidance they can apply on a cloud platform.
1. Starting Data Modeling from a Single Ticker Snapshot
When building a market data system, the most fundamental task is converting raw payloads returned by external sources into stable internal data structures. Take a typical snapshot as an example: the instrument code is GLM, the trading pair is GLMUSDT, the market type is CRYPTO, the latest traded price is 0.09109 USD, the 24-hour change is 0.002397, the change percentage is 2.703%, the open price is 0.0887, the high is 0.09369, the low is 0.0876, the market cap is about 91.6165 million USD, the market cap rank is 166, and the data update time is 2026-11-24 14:42:38.
These fields fall into four categories: identifiers (symbol, trading pair, market type), prices (last, open, high, low), statistics (change, change percentage, market cap, rank), and time (data update time). When modeling, treat identifiers as the primary key dimension, use high-precision fixed-point numbers rather than floating point for prices, distinguish “snapshot values” from “computed values” for statistics, and normalize time to a timezone-aware UTC timestamp.
from dataclasses import dataclassfrom decimal import Decimalfrom datetime import datetime, timezone@dataclass(frozen=True)class TickerSnapshot:symbol: str # Identifier: GLMpair: str # Trading pair: GLMUSDTmarket: str # CRYPTOlast: Decimal # Latest priceopen: Decimal # Open pricehigh: Decimal # High pricelow: Decimal # Low pricechange: Decimal # Change amountchange_pct: Decimal # Change percentagemarket_cap: Decimal # Market caprank: int # Rankts: datetime # Update time (UTC)
An immutable (frozen) dataclass is naturally thread-safe and easy to share in concurrent push scenarios. Using Decimal prevents prices like 0.0887 from accumulating error through binary floating-point representation.
2. Data Validation: The First Gate of Market Data Trustworthiness
The biggest risk in market data is not being “slow” but being “wrong.” A single incorrect high or low price can directly contaminate candlestick charts, indicators, and risk-control decisions. At least three layers of validation are recommended.
The first layer is structural validation: when required fields are missing, types do not match, or timestamps cannot be parsed, discard the record and count it toward a dirty-data metric. The second layer is business consistency validation, which is the most easily overlooked yet most critical:
- The high must be greater than or equal to the last, open, and low;
- The low must be less than or equal to the last and open;
- The change and change percentage should satisfy
change ≈ last - openandchange_pct ≈ change / open × 100%; - The market cap rank should be a positive integer within a reasonable range;
- The update time must not be significantly ahead of the current time (to prevent “future data” caused by clock drift).
Validating with the sample data: 0.09109 − 0.0887 = 0.00239, which matches the given 0.002397 within rounding error; 0.002397 / 0.0887 ≈ 2.70%, consistent with 2.703%; and the high 0.09369 and low 0.0876 correctly enclose both the last and open prices. This shows the snapshot is internally consistent and can enter downstream processing as a trusted sample.
The third layer is time-series validation: for the same instrument, new snapshot times must be monotonically increasing, and duplicate timestamps should be idempotently overwritten rather than appended, to avoid duplicate computation downstream.
def validate(s: TickerSnapshot) -> list[str]:errs = []if not (s.low <= s.open <= s.high and s.low <= s.last <= s.high):errs.append("price_out_of_range")if abs((s.last - s.open) - s.change) > s.open * Decimal("0.001"):errs.append("change_mismatch")if s.ts > datetime.now(timezone.utc):errs.append("future_timestamp")return errs
3. Collection and Transport: Turning an Uncertain External Stream into a Controllable Internal Stream
The core goal of the collection layer is decoupling and peak shaving. External market data interfaces usually have rate limits and occasional jitter, so business code should not call external sources synchronously. A more robust approach is to have the collector only responsible for fetching and preliminary validation, then write the standardized snapshots to a message queue, where downstream consumers subscribe as needed.
On Baidu AI Cloud, this architecture can map to a combination of general capabilities: use a message queue to handle high-frequency market events, use object storage to archive historical snapshots for backtracking and backfilling, use a container platform to host stateless collection and consumption processes for elastic scaling, and use logging and monitoring/alerting services to track latency and dirty-data ratios.
External market data source↓ (scheduled/incremental fetch, rate limiting and retries)Collector (structural validation + standardization)↓ (publish standardized events)Message queue (partitioned by instrument to guarantee per-instrument ordering)↓Consumer group: real-time push / indicator computation / persistence and archiving↓Object storage (historical archive) + monitoring/alerting (latency, dirty data)
Ordering guarantees are especially important: using the trading pair as the partition key ensures snapshots for the same instrument are consumed in order, making operations like “latest price overwrite” naturally idempotent.
4. Real-Time Display: From Server Push to Frontend Rendering
The display layer must solve two problems: how to deliver changes promptly, and how to avoid high-frequency refreshes overwhelming the browser. On the server side, use a long-lived connection to push incremental fields, sending only the columns that changed; on the frontend, use throttling and batched rendering to compress multiple updates within one second into a single repaint.
// Example: merge high-frequency updates per frame on the frontend to avoid per-tick repaintlet buffer = new Map();function onTick(t) { buffer.set(t.pair, t); }function flush() {for (const t of buffer.values()) renderRow(t);buffer.clear();requestAnimationFrame(flush);}requestAnimationFrame(flush);
For presentation, encode the change percentage with both color and arrows (to accommodate color-blind users), and clearly label the data update time and the market cap rank methodology, so users do not misread data from different statistical windows.
5. Observability and Alerting: Making Data Quality Measurable
A market data service must ship with its own “health report.” Collect at least four metrics: end-to-end latency (the time difference from the external timestamp to visibility on the frontend), dirty-data rate (the proportion of records failing validation), coverage completeness (the difference between instruments that should be subscribed and those actually received), and duplication rate (the number of duplicate records with the same timestamp). Set tiered alerts for latency and dirty-data rate, and attach sample raw payloads in alerts to quickly determine whether the issue is at the source or in parsing.
6. Common Pitfalls and a Delivery Checklist
- Storing prices as floating point: accumulated error over time will break indicator computation, so always use fixed-point numbers.
- Validating only structure but not business logic: inverted high/low prices are the most typical hidden failure.
- Tight coupling between collection and business logic: external jitter directly amplifies into business timeouts.
- Ignoring time zones: store all times in UTC and convert only at the display layer.
- No archiving: without historical snapshots, backfilling and post-mortem analysis become impossible.
A recommended delivery order is: define data structures → implement three-layer validation → decouple collection with a message queue → add incremental push and throttled rendering → complete metrics and alerting. Following this path, you can build a stable, scalable, and trustworthy market data display system on the cloud.
