Data Collection, Parsing, and Monitoring for Digital Asset Market Data

    This article walks through the practical engineering of digital asset market data pipelines, using a sample snapshot to explain how to model raw facts, derived metrics, and dimensions in separate layers. It covers field-level validation rules, a six-stage collection architecture that combines polling with incremental pulls, and semantic monitoring that treats freshness, completeness, consistency, and resource usage as first-class signals. The goal is to turn a working data pipeline into a trustworthy data foundation.

    1. Start With the Data Model, Not the Collector

    Before writing any collection code for a market data system, the first step is to define what a single snapshot actually contains. The following is a typical set of public market snapshot fields (values are for structure illustration only):

    1. Code: GLM
    2. Pair: GLMUSDT
    3. Market Type: CRYPTO
    4. Name: Golem
    5. Last Price: 0.09159
    6. Quote Currency: USD
    7. 24h Change: 0.002896
    8. 24h Change %: 3.266%
    9. Open: 0.08869
    10. High: 0.09368
    11. Low: 0.09759
    12. Market Cap: 90.5415M
    13. Market Cap Rank: 168
    14. Updated At: 2026-11-24 14:31:36

    This record looks simple, but it mixes four categories of information with completely different semantics: instrument identity (code, name, pair), market classification (market type, quote currency), price and statistical derivatives (last, open, high, low, change, change %), and aggregate metrics (market cap, rank, update time).

    The most common engineering mistake is to put everything into one wide table, which makes it impossible to distinguish raw facts from derived calculations later. A safer approach is layered modeling:

    • Fact layer: store only the raw fields provided directly by the exchange, such as last price, open, high, low, volume, and timestamp.
    • Derived layer: change, change %, market cap, rank, and similar values are computed or aggregated, and must be labeled with their calculation methodology and data version.
    • Dimension layer: instrument code, name, pair, and market type are dimension data with low change frequency, suitable for separate maintenance and version management.

    The direct benefit of this layering is that when the upstream changes the calculation window for change percentage (for example, from a fixed 24 hours to a rolling 24 hours), you only need to recompute the derived layer instead of replaying the entire fact layer history.

    2. Field-Level Validation: Keep Dirty Data Out Before Storage

    Market data is high-frequency and low-tolerance. One incorrect last price can trigger a wrong risk decision. Therefore, field-level validation rules must be established after parsing and before storage.

    At minimum, cover the following categories:

    1. Type and precision validation: use a high-precision decimal type for all price fields; never store them directly as binary floating point, to avoid accumulated error.
    2. Range and consistency validation: low ≤ open and last ≤ high; change and change % should satisfy change % ≈ change / (last - change) × 100%.
    3. Freshness validation: if the deviation between update time and current time exceeds a threshold (such as 5 minutes), mark the snapshot as stale.
    4. Enum validation: market type and quote currency must fall within a predefined enum set; when an unknown value appears, do not discard it, but route it to a quarantine area for manual confirmation.

    Example validation code:

    1. from decimal import Decimal
    2. def validate_snapshot(s):
    3. errors = []
    4. low, high = Decimal(s["low"]), Decimal(s["high"])
    5. open_, last = Decimal(s["open"]), Decimal(s["last"])
    6. if not (low <= open_ <= high and low <= last <= high):
    7. errors.append("price_out_of_range")
    8. change = Decimal(s["change"])
    9. pct = Decimal(s["change_pct"])
    10. base = last - change
    11. if base != 0:
    12. derived = (change / base * 100).quantize(Decimal("0.001"))
    13. if abs(derived - pct) > Decimal("0.05"):
    14. errors.append("change_pct_inconsistent")
    15. if s["market_type"] not in {"CRYPTO", "SPOT", "FUTURES"}:
    16. errors.append("unknown_market_type")
    17. return errors

    The purpose of validation is not rejection, but observability. Every flagged record should enter a quarantine area and be counted, forming data quality metrics, rather than being silently discarded.

    3. Collection Pipeline Design: Combine Scheduled Polling With Incremental Pulls

    Market data is usually obtained in two ways: push-based and polling-based. Either way, the pipeline should follow a six-stage structure: collect, buffer, parse, validate, store, and distribute. Each stage is decoupled for independent scaling and fault isolation.

    • Collection layer: pull snapshots on a fixed interval that matches the business latency requirement; for high-frequency scenarios, use incremental pulls that fetch only records with a timestamp greater than the last watermark.
    • Buffer layer: use a message queue to smooth peaks and valleys, preventing downstream parsing jitter from affecting collection stability.
    • Parsing layer: map fields from different sources to a unified internal model, normalizing units and precision.
    • Validation layer: apply the field-level rules from the previous section.
    • Storage layer: put hot data in memory or a time-series store, and archive cold data to object storage for traceability and auditing.
    • Distribution layer: push data to downstream consumers such as risk control, dashboards, and strategies through a subscription interface.

    Watermark mechanism example:

    1. def fetch_incremental(client, symbol, watermark):
    2. raw = client.query(symbol=symbol, since=watermark)
    3. new_wm = watermark
    4. for item in raw:
    5. ts = item["update_time"]
    6. if ts > watermark:
    7. new_wm = max(new_wm, ts)
    8. return raw, new_wm

    On the cloud, a message queue can handle buffering, object storage can handle archiving, a container platform can host parsing and validation services, and logging plus monitoring and alerting can handle observability. These are general capability categories; specific choices should be evaluated against the team’s existing technology stack and compliance requirements, rather than tied to a particular implementation.

    4. Monitoring and Alerting: Make the Pipeline Prove Its Own Health

    Market data pipeline failures are often silent: the job is still running, but the data has stopped updating. Monitoring must therefore cover business semantics, not just process liveness.

    Define four categories of metrics:

    1. Freshness: now - update_time; alert when it exceeds the threshold.
    2. Completeness: period-over-period fluctuation in record count; a sharp drop may indicate upstream rate limiting or a parsing failure.
    3. Consistency: validation failure rate and quarantine backlog.
    4. Resources: collection job latency, queue backlog length, and storage write failure rate.

    Alert severity can be tiered as follows: freshness breach is P1 (directly affects decisions), rising validation failure rate is P2 (data quality degradation), and resource alerts are P3 (capacity warnings). Each alert category should be bound to a runbook to avoid alert fatigue.

    5. Common Pitfalls and Engineering Recommendations

    • Do not store prices as floating point. Precision problems are amplified during long-period aggregation.
    • Do not blindly trust derived fields. Change %, market cap, and rank should be recomputable, with the calculation version retained.
    • Do not ignore time zones. Store in a standard time format with time zone, and localize only at the presentation layer.
    • Do not rely on a single collection source. Cross-validate across multiple sources, and when they disagree, trust the verifiable raw fields.
    • Do not degrade silently. Any dropping, zero-filling, or interpolation must leave a trace.

    6. Summary

    An ordinary-looking market snapshot contains six elements: identity, classification, price, derived statistics, and time. Building a layered model, field-level validation, a six-stage collection pipeline, and semantic monitoring around it is what upgrades a “working” data pipeline into a “trustworthy” data infrastructure. With the combination of general capabilities from Baidu AI Cloud, including message queues, object storage, container platforms, logging, and monitoring and alerting, teams can focus on data definitions and business semantics instead of rebuilding infrastructure.