Building a Reliable Market Data Pipeline: Collection, Validation, and Real-Time Display for Digital Asset Prices

    This article explains how to turn a simple-looking digital asset ticker snapshot into a stable, trustworthy, and traceable data service. It covers a three-layer domain model (identity, numeric, and metadata), a four-stage pipeline of fetching, normalization, validation, and persistence, layered storage and distribution using snapshot plus incremental channels with versioning, display practices that surface value, change, and data status, and observability with batch-level traceability. It also lists common pitfalls and practical engineering recommendations. Deployment examples reference general capabilities of Baidu AI Cloud without assuming any proprietary interface.

    1. Why Market Data Is Harder Than It Looks

    In digital asset trading applications, market data is the most fundamental and most underestimated component. A single snapshot usually contains only a few dozen scalar fields: trading pair identifier, last traded price, open, high, low, change ratio, turnover, market cap, rank, and data update time. There are not many fields, but turning them into a stable, trustworthy, and traceable service raises far more problems than the fields themselves.

    A typical ticker snapshot can be abstracted into the following structure:

    1. {
    2. "symbol": "GLMUSDT",
    3. "market_type": "CRYPTO",
    4. "base_asset": "GLM",
    5. "quote_asset": "USDT",
    6. "last_price": 0.09359,
    7. "open_24h": 0.09359,
    8. "high_24h": 0.09539,
    9. "low_24h": 0.09119,
    10. "change_24h": 0.0,
    11. "change_ratio_24h": 0.000,
    12. "market_cap": 93733100,
    13. "rank": 164,
    14. "source_time": "2026-12-01T19:55:40"
    15. }

    This record looks complete, yet it hides at least four engineering risks. First, time semantics are inconsistent: collection time, exchange matching time, and page rendering time may be mixed together. Second, numeric precision and units are inconsistent: the decimal places and dimensions of price, market cap, and change ratio need explicit conventions. Third, abnormal states are not expressed: for example, a last price exactly equal to the open price and a zero change may be genuine sideways movement, or simply data that has not refreshed. Fourth, version and provenance information is missing, so the source of a problem cannot be located when a dispute arises.

    2. Data Modeling: Upgrading Page Fields into a Domain Model

    A reliable market data service should define its domain model before discussing collection and display. It is advisable to split a ticker into three layers:

    1. Identity layer: trading pair, base asset, quote asset, market type. The identity layer must be normalized, for example with consistent uppercasing and a consistent separator, so that the same instrument never appears in multiple forms.
    2. Numeric layer: last price, 24-hour open/high/low, change amount, change ratio, turnover, market cap. The numeric layer must explicitly declare precision and units, and floating point must not be used directly for price arithmetic.
    3. Metadata layer: data source, collection batch, data time, quality flags. The metadata layer is the key to later troubleshooting and traceability.

    A practical modeling example:

    1. from dataclasses import dataclass
    2. from decimal import Decimal
    3. @dataclass(frozen=True)
    4. class TickerSnapshot:
    5. symbol: str # Normalized trading pair
    6. market_type: str # e.g. CRYPTO
    7. last: Decimal # Last price; Decimal avoids precision loss
    8. open_24h: Decimal
    9. high_24h: Decimal
    10. low_24h: Decimal
    11. change_24h: Decimal
    12. change_ratio: Decimal # Percentage value, e.g. 0.000 means 0%
    13. market_cap: Decimal
    14. rank: int
    15. source_time: str # ISO8601 with time zone
    16. quality_flags: tuple # Quality flags, e.g. ("STALE",)

    Using immutable objects together with a high-precision numeric type prevents downstream code from casually rewriting market data at the source. The quality flag field also makes it possible to distinguish “sideways movement” from “not updated”.

    3. Collection and Validation: Health Checks Before Data Enters the System

    The core goal of the collection layer is not to “get data” but to “get trustworthy data”. A four-stage pipeline is recommended: fetch, normalize, validate, persist.

    The normalization stage must unify units and time. Time unification is especially important: all timestamps must be converted to a standard format with a time zone, for example an ISO8601 string in UTC, and the display layer renders them in the user’s time zone.

    The validation stage should include at least the following rules:

    • Range check: the last price must fall between the day’s high and low (inclusive, allowing a very small tolerance).
    • Consistency check: the change ratio, change amount, and open price should satisfy an approximate relationship; a deviation beyond the threshold is flagged as suspicious.
    • Freshness check: if the gap between data time and current time exceeds a threshold, mark the data as stale rather than discarding it.
    • Monotonicity check: the high must not be lower than the open and the last price, and the low must not be higher than either.
    • Rank and market cap sanity check: rank must be a positive integer and market cap must be non-negative.

    Illustrative validation code:

    1. def validate(t: TickerSnapshot, max_stale_seconds: int = 60) -> list[str]:
    2. flags = []
    3. if not (t.low_24h <= t.last <= t.high_24h):
    4. flags.append("PRICE_OUT_OF_RANGE")
    5. expected_change = t.last - t.open_24h
    6. if abs(expected_change - t.change_24h) > t.last * Decimal("0.0001"):
    7. flags.append("CHANGE_INCONSISTENT")
    8. if t.market_cap < 0 or t.rank <= 0:
    9. flags.append("META_INVALID")
    10. return flags

    It is worth stressing that the purpose of validation is not to “block everything” but to “annotate uncertainty”. In a market data service, usable data with flags is usually more valuable than data that is simply discarded, because it lets downstream consumers decide their own fault-tolerance strategy.

    4. Storage and Real-Time Distribution: A Layered Design for Read-Heavy, Write-Heavy Workloads

    The access pattern of market data is typically write-heavy, extremely read-heavy, and latency-sensitive. A reasonable layering is:

    • Hot layer: an in-memory cache holding the latest snapshots to support millisecond reads.
    • Warm layer: a message queue carrying incremental updates for publish-subscribe distribution.
    • Cold layer: object storage or a time-series store holding historical snapshots for traceability and backtesting.

    On Baidu AI Cloud, a container platform can host stateless market data gateways, a message queue can handle incremental broadcasting, object storage can archive historical snapshots, and logging plus monitoring and alerting can track data freshness and validation failure rates. The point here is a combination of general capabilities, not any proprietary interface.

    For push delivery, a dual channel of “snapshot plus incremental” is recommended: a new client first fetches a full snapshot and then subscribes to increments; each increment carries a version number, and the client discards stale versions to avoid UI regressions caused by out-of-order delivery.

    1. Client subscription flow:
    2. 1) Fetch the full snapshot (version = 1024)
    3. 2) Subscribe to the incremental channel
    4. 3) On receiving a message with version <= 1024 -> discard it
    5. 4) On receiving version = 1025 -> apply it and update the local version

    5. Presentation: Turning Numbers into Explainable Information

    A common mistake in the presentation layer is showing only the last price while ignoring how trustworthy the data is. A better approach presents three layers of information at once: value, change, and status. For example, showing the data time and quality flags on screen tells the user whether “this is sideways movement” or “this is delayed data”.

    Change colors, precision truncation, and thousands separators should all be encapsulated in the presentation layer, so that individual pages do not implement their own formatting and end up with inconsistent conventions. For large values such as market cap, a human-readable format (for example in thousands or millions) is recommended, while keeping the raw value available for copying.

    6. Observability and Traceability: The Black Box of a Market Data System

    A market data system must be observable. At minimum, monitor four categories of metrics: collection success rate, validation failure rate, data freshness distribution, and end-to-end latency percentiles. Also keep paired records of raw payloads and normalization results, so that when a problem occurs you can quickly tell whether it is a collection bias, a normalization error, or a display convention issue.

    Traceability also requires data to carry a batch identifier. Take a snapshot whose data time is 2026-12-01 19:55:40: if monitoring shows that the whole batch has abnormal freshness, you can isolate that batch instead of investigating record by record.

    7. Common Pitfalls and Engineering Recommendations

    1. Using floating point for prices: use a high-precision decimal type, especially when computing change ratios and doing range comparisons.
    2. Treating “zero change” as normal: zero change may be genuine sideways movement or a collection failure, and freshness plus quality flags are needed to tell them apart.
    3. Storing only the latest value with no history: without historical snapshots, backtesting and troubleshooting become impossible.
    4. Letting each view implement its own formatting: diverging conventions create trust problems.
    5. Ignoring out-of-order and duplicate messages: the incremental channel must carry version numbers and handle idempotency.

    8. Conclusion

    The engineering difficulty of market data lies not in “fetching numbers” but in “defining clearly, validating thoroughly, distributing in order, and displaying trustworthily”. Build the three-layer model of identity, numeric, and metadata; turn validation into a pipeline that annotates rather than blocks; make distribution a dual channel of snapshot plus increment; and add solid monitoring and traceability. Together these turn an ordinary-looking ticker snapshot into a stable, reliable data service. Deploying and operating on the general cloud product capabilities of Baidu AI Cloud lets a team focus on data semantics and quality instead of rebuilding infrastructure.