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

    This article walks through the engineering challenges behind a single digital asset market data record and shows how to build a maintainable, observable market data service. Using a sample snapshot, it covers data modeling (symbol and pair normalization, fixed-point price handling, timestamp semantics), consistent definitions for 24h change and high/low windows, validation rules for detecting stale or out-of-range data, a layered storage and transport design, snapshot and incremental API patterns with a caliber version number, and observability metrics for latency, null rates, range violations, and prolonged zero volatility.

    1. Background: The Engineering Complexity Behind a Single Market Data Record

    In digital asset trading systems, market data is the most fundamental and most easily underestimated module. On the surface, a record only contains fields such as symbol, trading pair, last price, change, high and low, market cap, and update time. In real production environments, however, these fields involve a series of engineering problems: collection frequency, time alignment, precision handling, outlier removal, and consistency of definitions. This article uses a typical market snapshot as a sample to extract a general data model and processing pipeline, helping developers build a maintainable and observable market data service.

    The key fields of the sample data can be summarized as follows (values are for structural illustration only):

    1. {
    2. "symbol": "XXX",
    3. "pair": "XXXUSDT",
    4. "market_type": "CRYPTO",
    5. "last": 0.09359,
    6. "quote": "USD",
    7. "change_24h": 0.0,
    8. "change_pct_24h": 0.0,
    9. "open": 0.09359,
    10. "high": 0.09539,
    11. "low": 0.09119,
    12. "market_cap": 93733100,
    13. "rank": 164,
    14. "ts": "2026-12-01T19:53:38"
    15. }

    2. Data Modeling: Define Field Semantics First

    2.1 Identifier and Classification Fields

    symbol and pair describe the asset itself and the trading combination, while market_type identifies the market category. In engineering practice, these three should be treated as part of a composite primary key to avoid one asset with the same name overwriting another under a different market type. It is recommended to normalize everything to uppercase and perform trimming and case folding once at the ingestion layer.

    2.2 Price and Precision

    Price fields must be carried as fixed-point numbers or strings; storing and comparing them directly as binary floating point is prohibited. The reason is straightforward: a decimal like 0.09359 produces a tiny error under floating-point representation, and once accumulated in aggregate calculations (such as weighted average price or interval volatility), it amplifies into a visible deviation. The recommended approach:

    1. from decimal import Decimal, ROUND_HALF_UP
    2. def normalize_price(raw: str, scale: int = 8) -> Decimal:
    3. return Decimal(raw).quantize(Decimal(1).scaleb(-scale), rounding=ROUND_HALF_UP)

    2.3 Timestamp Semantics

    The update time must have an explicit timezone and precision. In practice, it is recommended to store everything internally as timezone-aware UTC and convert at the presentation layer according to user preference. It is also important to distinguish the “collection time” from the “source-marked time”; when the gap between them exceeds a threshold, a data freshness alert should be triggered.

    3. Change and High/Low: Consistency of Definitions Is the Core

    In the sample, the last price equals the open price, the 24h change amount is zero, and the change percentage is 0.000%, which is exactly why the definition problem matters. The change percentage must specify three things: which moment the base price is taken from, whether a rolling 24-hour window is used, and whether it is split by calendar day. Different choices will produce multiple “correct” change percentages at the same moment.

    It is recommended to converge the calculation logic into a single function and record it in metadata:

    1. def change_pct(last: Decimal, base: Decimal) -> Decimal:
    2. if base == 0:
    3. return Decimal("0")
    4. return ((last - base) / base * 100).quantize(Decimal("0.001"))

    The high and low prices should be strictly bound to the time window and recomputed whenever the window rolls, avoiding the logical contradiction of a “last price outside the interval.”

    4. Anomaly Detection: Silent Risks in Low-Volatility Scenarios

    Zero change does not necessarily mean a data error, but persistent zero volatility is often a signal that the collection pipeline has been interrupted. Practical validation rules include:

    • The last price must fall within the day’s high-low range; otherwise it is judged as dirty data;
    • The change percentage and change amount must have the same sign and satisfy change ≈ last - base;
    • Market cap and rank should undergo monotonicity sanity checks, and a sudden rank jump requires secondary confirmation;
    • If price and update time remain unchanged for N consecutive cycles, trigger a pipeline health check.
    1. def is_sane(rec) -> bool:
    2. if not (rec.low <= rec.last <= rec.high):
    3. return False
    4. if rec.change_pct * rec.change_24h < 0:
    5. return False
    6. return rec.ts_age_seconds < 90

    5. Storage and Transport: A Layered Design

    The collection layer is responsible for high-frequency pulling and raw persistence; it is recommended that raw payloads go into object storage for cold backup. The compute layer handles window aggregation and definition unification, writing results into a low-latency key-value store. The presentation layer subscribes to incremental updates through a message queue, while a monitoring and alerting service observes latency, null rate, and out-of-range rate. A container platform hosts stateless compute tasks, making it easy to scale in and out elastically according to market volatility.

    6. Presentation and API Design

    The external API should provide both snapshot and incremental forms: the snapshot returns all fields along with a data timestamp and a caliber version number; the incremental form pushes a list of changes, and the client merges by version number. An illustrative response structure:

    1. {
    2. "data": { "symbol": "XXX", "last": "0.09359", "ts": "2026-12-01T19:53:38Z" },
    3. "meta": { "caliber_version": "v1", "source_ts": "2026-12-01T19:53:35Z" }
    4. }

    Exposing the caliber version number is a key design for reducing cross-team communication costs; when disputes arise, you can quickly determine whether it is a collection problem or a computation problem.

    7. Observability and Drills

    Observability for a market data service should cover at least four types of metrics: collection latency, field null rate, interval violation rate, and duration of zero volatility. Combined with a logging service for structured search, historical snapshots should be replayed regularly for regression validation. In general practice, Baidu AI Cloud typically recommends combining monitoring and alerting with a logging service to close this loop; developers can build a similar setup using comparable general-purpose capabilities.

    8. Summary

    The difficulty of market data lies not in the number of fields but in precise semantics and unified definitions. If you get these five things solid—normalized identifiers, fixed-point prices, standardized timestamps, rule-based validation, and versioned calibers—then even a “seemingly informationless” record like zero change can be correctly interpreted rather than misjudged as a failure.