Building a Production-Ready Market Data Pipeline: Collection and Parsing Practices for Digital Assets

    This article walks through the engineering of a digital asset market data pipeline, using a structured ticker sample to derive a general-purpose field model across four dimensions: identity, price, statistics, and time. It covers a layered collection design that prioritizes stability, a three-tier validation approach that blocks dirty data before storage, storage choices driven by access patterns, and common pitfalls such as floating-point price storage, trusting upstream derived fields, timezone mixing, and non-idempotent writes. Readers will learn how to build a reproducible, scalable, and operable market data foundation with data staleness monitoring at its core.

    1. Introduction: Why Market Data Pipelines Need Engineering

    In the development of digital asset systems, market data is often the first thing to be integrated, yet it is the most easily underestimated. Many teams simply fetch a snapshot once and print it to the console during the prototype stage. Only when they need to support strategy backtesting, risk dashboards, or real-time alerts do they discover inconsistent time baselines, precision loss, and arbitrary handling of missing values, which make downstream analytical conclusions impossible to reproduce.

    This article starts from a set of structured ticker samples, abstracts a general-purpose field model, and presents a practical collection and parsing solution. The sample contains the following elements: symbol code GLM, trading pair GLMUSDT, market type CRYPTO, latest price 0.09359 USD, 24-hour change 0.00009989, change percentage 0.107%, open price 0.09349, high price 0.09539, low price 0.09119, market cap of roughly USD 93.7331 million, market cap rank 164, and update time 2026-12-01 19:51:20.

    The value of this data lies not in any specific number but in the fact that it fully covers the four categories of information required for market data modeling: identity, price, statistics, and time. Once these four categories are clearly abstracted, the skeleton of the pipeline takes shape.

    2. Field Semantics: From Sample to General Model

    2.1 Identity Dimension

    The symbol code, trading pair, and market type together form a composite primary key. A trading pair is concatenated from a base asset and a quote asset, while the market type distinguishes different matching mechanisms such as spot and derivatives. In engineering practice, it is advisable to normalize these into immutable enumerations to avoid free-text input from upstream sources, which can produce multiple spellings for the same meaning.

    2.2 Price Dimension

    The latest price, open price, high price, and low price form the core four prices of a candle. Note that the high and low describe extreme values within a statistical interval, whereas the latest price is an instantaneous value at the end of that interval; the two must not be conflated. The change amount and change percentage are derived quantities that should be calculated from the open price and latest price rather than collected independently, which otherwise easily produces self-contradictory data.

    2.3 Statistics Dimension

    Market cap and market cap rank are global aggregate metrics, usually estimated by multiplying on-chain circulating supply by price, and different data sources may use different definitions. Therefore, these fields are suitable for trend observation but not as a strongly consistent basis for trading decisions.

    2.4 Time Dimension

    The update time defines the freshness boundary of the data. All downstream computations should explicitly carry this timestamp, store it uniformly in UTC, and let the presentation layer convert it to the user’s timezone.

    3. Collection Layer Design: Stability First

    The core goal of the collection layer is “no loss, no duplication, no disorder.” A layered fetching structure with local queue buffering is recommended: scheduled tasks fetch snapshots at fixed intervals, write them to a local persistent queue, and a consumer then writes them to storage in batches. This way, data is not lost outright even if a downstream system is briefly unavailable.

    1. import time
    2. from dataclasses import dataclass, asdict
    3. @dataclass(frozen=True)
    4. class TickerSnapshot:
    5. symbol: str # trading pair
    6. market_type: str # market type
    7. last: str # latest price, kept as string to preserve precision
    8. open: str
    9. high: str
    10. low: str
    11. quote_volume: str
    12. market_cap: str
    13. rank: int
    14. updated_at: str # UTC ISO8601
    15. def normalize(raw: dict) -> TickerSnapshot:
    16. return TickerSnapshot(
    17. symbol=raw["symbol"].upper(),
    18. market_type=raw["market_type"].upper(),
    19. last=raw["last"],
    20. open=raw["open"],
    21. high=raw["high"],
    22. low=raw["low"],
    23. quote_volume=raw["quote_volume"],
    24. market_cap=raw["market_cap"],
    25. rank=int(raw["rank"]),
    26. updated_at=raw["updated_at"],
    27. )
    28. def collect_loop(fetch, sink, interval=5):
    29. while True:
    30. try:
    31. sink.append(asdict(normalize(fetch())))
    32. except Exception as exc:
    33. # record a metric instead of raising, to keep the loop alive
    34. sink.record_error(exc)
    35. time.sleep(interval)

    There are two key conventions here: prices are always carried as strings to avoid binary floating-point errors being amplified during long-period aggregation; and the collection loop catches exceptions internally and reports metrics rather than letting a single failure terminate the entire task.

    4. Parsing and Validation: Blocking Dirty Data Before Storage

    Validation rules are best applied in three progressive layers: structure, range, and logic. The structure layer checks required fields and types; the range layer checks that prices must be positive and rank must be a positive integer; the logic layer checks that the high is not lower than the low, the latest price falls within the extreme range, and the direction of the change percentage matches the change amount.

    1. from decimal import Decimal
    2. def validate(s: TickerSnapshot) -> list[str]:
    3. errs = []
    4. last, high, low = Decimal(s.last), Decimal(s.high), Decimal(s.low)
    5. if last <= 0 or high <= 0 or low <= 0:
    6. errs.append("non_positive_price")
    7. if high < low:
    8. errs.append("high_lt_low")
    9. if not (low <= last <= high):
    10. errs.append("last_out_of_range")
    11. if s.rank <= 0:
    12. errs.append("invalid_rank")
    13. return errs

    Derived metrics are uniformly computed from data that has passed validation, ensuring a single source of truth:

    1. def derive(s: TickerSnapshot) -> dict:
    2. o, last = Decimal(s.open), Decimal(s.last)
    3. diff = last - o
    4. pct = (diff / o * 100) if o else Decimal(0)
    5. return {"change": str(diff), "change_pct": round(pct, 3)}

    5. Storage and Query: Choosing by Access Pattern

    Market data is a typical “write-heavy, read-light, time-range scan” workload. Raw snapshots are best stored in a time-series database or columnar storage, partitioned by symbol and time; aggregated minute-level and hour-level data should be placed in separate tables for fast dashboard queries. Object storage can be used for long-term archival, message queues to decouple collection from consumption, container platforms to host stateless collection processes for elastic scaling, and logging and monitoring services to observe metrics such as collection latency, failure rate, and data staleness.

    It is worth emphasizing that data staleness should be a first-class monitoring metric: trigger an alert immediately when the latest timestamp lags behind the current time beyond a threshold. This reflects true availability better than simply monitoring whether the process is alive.

    6. Common Pitfalls and Best Practices

    First, do not store prices using floating-point types, as long-period summation accumulates errors; second, do not blindly trust upstream derived fields, always recompute locally; third, do not ignore timezones, as mixing local time will completely distort cross-day statistics; fourth, do not retry writes without an idempotency key, as duplicate data will pollute average-type metrics; fifth, retain the original payload for every data change to facilitate problem tracing.

    7. Conclusion

    By treating market data as a first-class citizen, modeling the four field categories of identity, price, statistics, and time in layers, decoupling collection from validation, splitting storage by access pattern, and pairing it with a monitoring system centered on staleness, you can build a reproducible, scalable, and operable market data foundation. Deploying it on general-purpose capabilities such as the container platform, message queue, and monitoring and alerting offered by Baidu AI Cloud can further reduce operational overhead, letting the team focus its energy on the analytical logic itself.