Market Data Collection, Validation, and Real-Time Display for Digital Assets

    This article walks through the practical engineering of digital asset market data, from modeling a single ticker snapshot to running a reliable real-time pipeline. It explains how to separate raw fields from derived metrics, how to build a three-layer validation pipeline covering structure, consistency, and time-series checks, and why collection time must be distinguished from data update time. It also compares snapshot polling with incremental push, outlines a two-tier caching and display strategy with consistent precision, and lists the observability metrics and fallback paths needed to keep market data trustworthy.

    1. Start With the Data Model: Lessons From a Single Snapshot

    In digital asset application development, the most fundamental and most underestimated step is mapping a market data snapshot accurately into a structure that can be computed, stored, and displayed. Take a captured sample: a trading instrument priced in USD, with a latest price of about 0.09119, a 24-hour change of about 0.002497, a change of about 2.815%, an open of about 0.08869, a high of about 0.09368, a low of about 0.08759, a market cap of about 90.5415 million USD, a market cap rank of about 168, and a data update time of 2026-11-24 14:29:37.

    These fields look simple, but they fall into four categories with completely different semantics:

    • Identifier fields: symbol, trading pair, market type, quote currency. They determine ownership and comparability of the data.
    • Price fields: last price, open, high, low. They describe the price distribution within a time window.
    • Derived fields: change, change percentage, market cap, rank. They are not raw observations but calculation or aggregation results.
    • Metadata fields: data update time, data source tag. They determine the credibility and timeliness of the data.

    The most common mistake in practice is treating derived fields the same as raw fields, storing them directly and depending on them long term. Once the upstream definition changes (for example, market cap is calculated by circulating supply instead of total supply), historical data loses comparability. It is therefore recommended to explicitly distinguish raw from derived at the data model layer:

    1. from dataclasses import dataclass
    2. from decimal import Decimal
    3. @dataclass(frozen=True)
    4. class TickerSnapshot:
    5. symbol: str # Instrument symbol
    6. pair: str # Trading pair
    7. market_type: str # Market type
    8. quote_currency: str # Quote currency
    9. last: Decimal # Latest price
    10. open: Decimal # Open price
    11. high: Decimal # High price
    12. low: Decimal # Low price
    13. ts_utc: int # Collection timestamp (seconds)
    14. @property
    15. def change(self) -> Decimal:
    16. return self.last - self.open
    17. @property
    18. def change_pct(self) -> Decimal:
    19. if self.open == 0:
    20. return Decimal(0)
    21. return (self.change / self.open) * Decimal(100)

    There are two key design decisions here. First, prices always use a high-precision decimal type rather than floating point, avoiding tail differences when decimals like 0.09119 are accumulated and compared. Second, the change and change percentage exist as computed properties rather than persisted fields, ensuring a single source of truth for their definition.

    2. Data Validation: Turning “Looks Normal” Into “Can Be Trusted”

    The real difficulty in a market data stream is not acquisition but identifying and isolating dirty data. A mature validation pipeline usually has three layers.

    The first layer is structural validation, confirming that fields are complete, types are correct, and enum values are valid. Fields such as market type and quote currency should be enumerated; unknown values should go to a quarantine area rather than be discarded outright.

    The second layer is range and consistency validation. Prices must be positive; the high should be greater than or equal to the last price and the low; the low should be less than or equal to the last price and the open; the change percentage should be mathematically consistent with the change and the open. The following logic can be used for a quick screen:

    1. def is_consistent(s: TickerSnapshot) -> bool:
    2. if s.last <= 0 or s.low <= 0:
    3. return False
    4. if not (s.low <= s.last <= s.high):
    5. return False
    6. if not (s.low <= s.open <= s.high):
    7. return False
    8. # Change percentage consistency, allowing 0.05 percentage points of float/definition error
    9. return abs(s.change_pct - Decimal("2.815")) < Decimal("0.05")

    The third layer is time-series plausibility validation, comparing against a historical window. If the latest price deviates from the past N sample points beyond a configured threshold and volume has not increased accordingly, it is more likely a data error than a real market move. It is important to emphasize that thresholds must be adjusted dynamically based on the instrument’s own volatility; using a fixed absolute threshold for low-priced instruments will cause many false positives.

    3. Time Semantics: Update Time vs. Collection Time

    The “update time” in the sample is data-side time, while what the system really cares about is “collection time” and “data age”. The difference between the two forms the delay, which is the core indicator for deciding whether market data is usable. In engineering, it is recommended to:

    • Store all times in UTC uniformly, and format them by user time zone at the display layer;
    • Attach data_age = now() - ts_utc to each record and expose it in API responses;
    • When data_age exceeds a threshold, the frontend should explicitly mark “data may be delayed” rather than silently showing stale values.

    For aggregate metrics such as market cap and rank, the calculation window must also be recorded. Rank is a relative quantity that drifts as other instruments across the market change, so it is not suitable as a basis for business logic and is only suitable for display.

    4. Architecture Choices: Snapshot Polling vs. Incremental Push

    There are mainly two modes for acquiring market data. Snapshot polling is simple to implement and has no state consistency burden, making it suitable for low-frequency metrics such as rank and market cap; incremental push has low latency and high resource efficiency, making it suitable for high-frequency metrics such as price. Mature systems often mix both: price goes through the push channel, and aggregate metrics go through scheduled snapshots.

    A simplified background task skeleton is as follows:

    1. import asyncio, time
    2. async def snapshot_loop(emit, interval=15):
    3. while True:
    4. snap = await fetch_ticker() # Data source is a general market data API
    5. if is_consistent(snap):
    6. await emit(snap) # Write to cache and broadcast
    7. else:
    8. quarantine(snap) # Quarantine and count
    9. await asyncio.sleep(interval)

    In terms of deployment, stateless collection processes can run on a container platform and scale horizontally; raw data can land in object storage to support retrospective analysis; a message queue handles decoupling and peak shaving between collection and display; logging services and monitoring alerts continuously observe metrics such as collection success rate, data age, and validation failure rate. In a cloud environment such as Baidu AI Cloud, all of these capabilities can be implemented with general-purpose offerings, without binding to proprietary APIs.

    5. Caching and Display: Coexisting Low Latency and Consistency

    The display layer is recommended to use two-level caching: a local in-memory cache handles extremely high-frequency reads, and a distributed cache handles cross-instance sharing. For update strategies, price data uses “write-time update with short TTL as a fallback”, while aggregate data uses “scheduled recomputation with long TTL”.

    Frontend rendering needs to avoid two pitfalls. One is full refresh causing layout jitter; only changed numeric nodes should be updated. The other is inconsistent precision display; showing 0.09119 as 0.09 in one place and 0.0912 in another on the same page will make users doubt data reliability. It is recommended to centrally define the price precision and thousands separator rules for each instrument in configuration.

    1. {
    2. "symbol": "GLM",
    3. "price_decimals": 5,
    4. "change_decimals": 6,
    5. "percent_decimals": 2,
    6. "quote_currency": "USD"
    7. }

    6. Observability and Fault Tolerance

    Operations for a market data system can be summarized in four metrics: collection success rate, end-to-end latency, validation failure rate, and cache hit rate. Any metric degradation should trigger an alert. At the same time, fallback paths need to be designed: when upstream is unavailable, display the most recent trusted snapshot with its time labeled; when the validation failure rate spikes, automatically switch to a more conservative polling interval to avoid dirty data polluting downstream calculations.

    7. Summary

    A seemingly ordinary market data record contains four semantic categories: identifier, price, derived, and metadata. Making it a reliable service requires distinguishing raw values from derived values at the modeling stage, building three lines of defense (structure, consistency, and time series) at the validation stage, strictly separating data time from collection time in time semantics, mixing polling and push by metric characteristics in architecture, and unifying precision, controlling latency, and improving alerts and fallback at the display and operations levels. Following this path, market data can move from “visible” to “dependable”.