Collecting, Validating, and Displaying Digital Asset Market Data in Real Time
This article walks through the engineering practices behind a single spot market snapshot, covering how to model the data, validate it, and serve it in real time. It breaks a sample snapshot into trading pair, price (OHLC), and derived statistics dimensions, then explains consistency, freshness, and precision checks with sample Python code. It also outlines a four-layer architecture for collection, computation, storage, and distribution, along with caching and consistency strategies, observability and alerting, and cloud deployment with cost considerations. Readers will learn how to keep market data trustworthy under high volatility by separating derived metrics from raw prices, treating timestamps as versions, and designing graceful degradation upfront.
1. Data Modeling from a Single Market Snapshot
The source material provides a typical spot market snapshot: symbol GLM, trading pair GLMUSDT, market type CRYPTO, last traded price 0.09359 USD, 24-hour change 0 and change percentage 0.000%, open price 0.09359, high 0.09539, low 0.09119, market cap roughly 93.7331 million USD, market cap rank 164, and an update time of 2026-12-01 19:56:40.
This record is information-dense, but storing it directly is not appropriate. From an engineering standpoint, it should first be abstracted into three layers:
- Trading pair dimension: a unique key composed of the base asset and the quote asset, with market type as a partitioning dimension;
- Price dimension: the last price, open, high, and low form the OHLC skeleton;
- Statistics dimension: change amount, change percentage, market cap, and rank are derived metrics and should not be stored mixed with raw prices.
Derived metrics must be annotated with their calculation basis. For example, the change percentage is usually computed as (last price - baseline price 24 hours ago) / baseline price. In this example, the change amount is 0 and the change percentage is 0.000%, and the last price is exactly equal to the open price, which indicates the price did not move within the statistics window. This is a normal state of low volatility or unrefreshed data, not an anomaly.
2. Field Validation: Turning “Looks Normal” into “Provably Normal”
The most common failure in a market data service is not an unavailable interface, but silent data errors. Three types of checks are recommended:
- Consistency check: high ≥ last ≥ low; here 0.09539 ≥ 0.09359 ≥ 0.09119 holds.
- Time freshness check: if the update time deviates from server time beyond a threshold, mark the data as stale.
- Precision check: align the number of decimal places of the price with the precision of the quote asset to avoid accumulated floating-point error.
Illustrative pseudocode:
def validate(snapshot, now, max_lag_seconds=30):p, h, l = snapshot.last, snapshot.high, snapshot.lowassert h >= p >= l > 0, "price range violated"lag = now - snapshot.tsreturn {"fresh": lag <= max_lag_seconds,"lag_seconds": lag,"derived_ok": abs(snapshot.change_pct) < 1e6,}
For derived metrics, it is recommended to use fixed-point or high-precision decimal types for storage, eliminating drift from binary floating point during long-period aggregation.
3. Layered Architecture: Decoupling Collection, Computation, and Distribution
A four-layer structure is recommended:
- Collection layer: combine scheduled polling with incremental fetching, shard by trading pair, and avoid concentrated requests to a single point;
- Computation layer: maintain the baseline price within a sliding window and produce derived fields such as change percentage, amplitude, and market cap rank;
- Storage layer: put hot data into an in-memory cache, and land historical data in time-series or columnar storage, partitioned by time for easy lookback;
- Distribution layer: expose batch query interfaces and incremental push channels externally, using a “update on change” strategy for pushing to reduce bandwidth.
The collection layer needs exponential backoff retries and circuit breaking to prevent upstream jitter from triggering an avalanche:
async def fetch_with_backoff(client, pair, attempt=0):try:return await client.get(pair)except TransientError:if attempt >= 5:raiseawait asyncio.sleep(min(2 ** attempt * 0.2, 5))return await fetch_with_backoff(client, pair, attempt + 1)
4. Caching and Consistency Strategy
Market data is read-heavy and write-light, making it suitable for multi-level caching: a local cache handles hot trading pairs, while a distributed cache handles the full set. The key is to set clear invalidation rules—use the data’s own timestamp as the version number, and only allow a newer version to overwrite an older value, thereby avoiding price rollback caused by out-of-order returns.
On the push side, a “snapshot + incremental” model is recommended: send a full snapshot when the connection is established, then push only changed fields, with the client merging locally. After reconnection, re-fetch the snapshot to align state.
5. Observability and Alerting
Metrics that must be monitored include: collection success rate, data latency percentiles, validation failure rate, cache hit rate, push connection count, and reconnection count. Alerts should be tiered: latency exceeding a threshold triggers a notification, and consecutive validation failures trigger a critical alert and automatically degrade to a “data temporarily unavailable” message, avoiding outputting suspicious values to the frontend.
6. Cloud Deployment and Cost Considerations
In a cloud environment, a container platform can host collection and computation services for elastic scaling, a message queue can buffer traffic peaks, object storage can archive historical snapshots, and logging and monitoring/alerting systems handle tracking and notification. Baidu AI Cloud offers corresponding product forms across these general capability categories, which can be combined according to business scale, using elastic scaling and hot/cold tiering to control costs.
7. Summary
Behind a single market snapshot lies a complete engineering pipeline: standardized modeling, strict validation, a layered architecture, clear consistency rules, and thorough observability. Only by separating derived metrics from raw prices, treating timestamps as versions, and designing degradation strategies upfront can trustworthy data be continuously delivered under high-volatility conditions.
