Market Data Collection and Parsing for Digital Assets: A Practical Guide

    This article walks through the practical engineering of collecting and parsing digital asset market data. Starting from a sample market snapshot, it explains how to classify fields into atomic observations, derived metrics, and aggregate statistics, how to normalize timestamps to UTC, and how to apply hard and soft data quality checks before storage. It also covers a decoupled pipeline design, numeric precision handling, and monitoring priorities, showing how to build a market data path that supports real-time display, historical replay, and auditing.

    1. Starting With a Single Market Snapshot

    In digital asset application development, market data is the most fundamental input and also the most error-prone. The following is a typical set of public market snapshot fields (sample data, used only to illustrate the structure):

    1. {
    2. "symbol": "GLMUSDT",
    3. "market_type": "CRYPTO",
    4. "base_asset": "GLM",
    5. "quote_asset": "USDT",
    6. "last_price": 0.09109,
    7. "quote_currency": "USD",
    8. "change_24h": 0.002397,
    9. "change_rate_24h": 2.703,
    10. "open_24h": 0.08869,
    11. "high_24h": 0.09368,
    12. "low_24h": 0.08759,
    13. "market_cap": 90541500,
    14. "market_cap_rank": 168,
    15. "update_time": "2026-11-24 14:34:37"
    16. }

    This record carries a lot of information, but storing it directly or feeding it into calculations introduces several risks: the time field lacks a timezone, the change amount and change rate are coupled by precision, market cap and rank are aggregate metrics rather than individual trades, and the update time marks the snapshot moment rather than the validity window of the data. Before discussing storage and computation, engineering work must first draw clear semantic boundaries.

    2. Field Semantics: Grouping Metrics Into Three Layers

    It is advisable to divide market data fields into three layers, each with its own update strategy and validation rules.

    The first layer is atomic observations, including the latest price, open price, high price, and low price. They come directly from matching results and must satisfy a monotonic relationship: low ≤ open ≤ last ≤ high (in extreme one-sided markets the open price may sit on a boundary of the range, but the containment relationship must always hold).

    The second layer is derived metrics, including the 24-hour change amount and change rate. They satisfy change = last - open and rate = change / open * 100. In the example, 0.09109 - 0.08869 = 0.00240, which differs in the last digit from the given 0.002397, indicating that the upstream applied rounding or used a higher-precision intermediate value. The engineering principle is to compute with high-precision intermediate values and format only at the presentation layer, avoiding back-calculating computed values from display values.

    The third layer is aggregate statistics, including market cap and market cap rank. They depend on estimates of the circulating supply across the whole market, and different data sources may use different definitions, so they are only suitable for trend display and not as a basis for reconciliation.

    3. Time and Timezone: The Most Underrated Pitfall

    update_time is the moment the snapshot was generated and does not mean the data is still valid along the pipeline. When landing data, it is recommended to record three timestamps: the collection time (local system clock), the snapshot time (marked by the source), and the ingestion time. The differences among the three can be used to compute pipeline latency and serve as a basis for judging data freshness.

    1. from datetime import datetime, timezone, timedelta
    2. def normalize(ts: str, source_tz: str = "UTC") -> datetime:
    3. dt = datetime.strptime(ts, "%Y-%m-%d %H:%M:%S")
    4. tz = timezone(timedelta(hours=8)) if source_tz == "UTC+8" else timezone.utc
    5. return dt.replace(tzinfo=tz).astimezone(timezone.utc)

    Storing everything in UTC and displaying in the business timezone is the lowest-cost convention for cross-team collaboration.

    4. Data Quality Validation Rules

    Set up a validation gate before writing to storage, with rules divided into hard checks and soft checks. A failed hard check leads to immediate discard and is counted in anomaly metrics; a failed soft check is tagged and routed into a review queue.

    • Hard checks: prices must be positive; the high/low range containment must hold; the absolute change rate must be within a reasonable threshold (for example, exceeding ±50% in a single period requires manual confirmation); timestamps must not be in the future.
    • Soft checks: the latest price deviates from the previous snapshot by more than a configured multiple; the market cap rank jumps significantly; volume and price movement clearly diverge in direction.

    Illustrative implementation:

    1. def hard_check(r: dict) -> bool:
    2. if r["low_24h"] <= 0 or r["last_price"] <= 0:
    3. return False
    4. if not (r["low_24h"] <= r["open_24h"] <= r["high_24h"]):
    5. return False
    6. if abs(r["change_rate_24h"]) > 50:
    7. return False
    8. return True

    5. Storage and Computation Pipeline Design

    The recommended decoupled structure is: the collector handles pulling data and retaining raw payloads, the message queue handles peak shaving and decoupling, stream computing handles cleaning and aggregation, object storage handles cold data archiving, and logging plus monitoring and alerting handle observability. General-purpose capabilities from Baidu AI Cloud, such as message queues, object storage, logging, and monitoring and alerting, can support this layering without creating a strong dependency between the collection side and the computation side.

    Raw payloads should be retained verbatim to facilitate issue tracing and rule iteration; cleaned structured data should be written with time-based partitions, using the UTC date as the partition key, which can significantly reduce scan costs for historical replay.

    1. Collector -> Raw payload archive (object storage)
    2. -> Message queue (topic: market_snapshot)
    3. -> Stream cleaning (validation/standardization)
    4. -> Structured storage (daily partitions) + real-time metrics dashboard

    6. Precision and Numeric Types

    Price fields must not use binary floating point directly for equality comparison or accumulation. A workable approach is to carry decimals as strings at the transport layer, use fixed-point or high-precision decimal types at the storage layer, and convert only at display time. For ratios such as the change rate, explicitly define the number of decimal places and the rounding mode (for example, round half up to three decimals) and fix it in the documentation, avoiding reconciliation discrepancies caused by upstream and downstream implementing it separately.

    7. Monitoring and Alerting

    What needs monitoring is not only service liveness but also the correctness of the data itself: collection latency percentiles, hard check failure rate, field missing rate, snapshot staleness duration, and price deviation of the same symbol across multiple sources. Alerts should be tiered: a sudden spike in the hard check failure rate is high priority, while jitter in rank-type aggregate metrics is better placed in a daily report.

    8. Summary

    The difficulty of market data processing lies not in pulling data but in semantic alignment and quality gating. Splitting fields into atomic, derived, and aggregate layers, unifying the time baseline, front-loading hard checks, retaining raw payloads, and then using general cloud capabilities to achieve decoupling and observability can build a reliable pipeline that supports real-time display, historical replay, and auditable tracing.