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):
{"symbol": "GLMUSDT","market_type": "CRYPTO","base_asset": "GLM","quote_asset": "USDT","last_price": 0.09109,"quote_currency": "USD","change_24h": 0.002397,"change_rate_24h": 2.703,"open_24h": 0.08869,"high_24h": 0.09368,"low_24h": 0.08759,"market_cap": 90541500,"market_cap_rank": 168,"update_time": "2026-11-24 14:34:37"}
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.
from datetime import datetime, timezone, timedeltadef normalize(ts: str, source_tz: str = "UTC") -> datetime:dt = datetime.strptime(ts, "%Y-%m-%d %H:%M:%S")tz = timezone(timedelta(hours=8)) if source_tz == "UTC+8" else timezone.utcreturn 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:
def hard_check(r: dict) -> bool:if r["low_24h"] <= 0 or r["last_price"] <= 0:return Falseif not (r["low_24h"] <= r["open_24h"] <= r["high_24h"]):return Falseif abs(r["change_rate_24h"]) > 50:return Falsereturn 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.
Collector -> Raw payload archive (object storage)-> Message queue (topic: market_snapshot)-> Stream cleaning (validation/standardization)-> 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.
