Digital Asset Market Data Collection and Parsing: A Practical Guide
This article walks through the practical engineering of collecting and parsing digital asset market data. Using a sample GLMUSDT snapshot, it explains why raw quotes are hard to use directly, proposes a four-layer data model (identifier, price, statistics, metadata), defines five validation and cleaning rules, and outlines a dual-channel collection design combining scheduled snapshots with incremental updates. It also highlights common pitfalls and engineering recommendations to make market data verifiable, replayable, and aggregatable.
1. Background: Why Raw Market Data Is Hard to Use Directly
The source material provides a typical market snapshot: a digital asset with code GLM, trading pair GLMUSDT, market type CRYPTO, last price 0.09359 USD, 24-hour change of 0 and change percentage of 0.000%, open price 0.09359, high 0.09539, low 0.09119, market cap of about 93.7331 million USD, market cap rank 164, and update time 2026-12-01 19:54:36.
This record is information-dense, but storing it directly or using it in calculations introduces several problems: inconsistent field naming, ambiguous time semantics, inconsistent numeric precision, a logical conflict between the 24-hour change amount and change percentage, and mixed market cap units of “ten thousand” and “USD”. In engineering terms, this “human-readable snapshot” must first be converted into “machine-verifiable structured data”.
2. Abstract Data Model: Splitting the Snapshot into Four Entity Layers
It is recommended to abstract a market snapshot into four layers to avoid the semantic confusion caused by flat fields.
- Identifier layer: asset code, trading pair, market type. A trading pair is usually formed by concatenating a base asset and a quote asset, and should be split and stored separately to allow aggregation by quote currency.
- Price layer: last price, open price, high, low. These four must satisfy the containment relation low ≤ open/last ≤ high.
- Statistics layer: 24-hour change amount, change percentage, market cap, market cap rank. This layer depends on a statistical window, so the window start and end times must be recorded additionally.
- Metadata layer: data update time, data source identifier, collection delay.
A sample structure is as follows:
{"symbol": "GLM","pair": { "base": "GLM", "quote": "USDT" },"market": "CRYPTO","price": { "last": "0.09359", "open": "0.09359", "high": "0.09539", "low": "0.09119" },"stats": { "change_24h": "0", "change_pct_24h": "0.000", "market_cap": "937331000", "rank": 164 },"meta": { "ts": "2026-12-01T19:54:36", "source": "snapshot", "delay_ms": 0 }}
3. Validation and Cleaning: Five Rules That Must Pass
Data credibility comes from validation, not collection frequency. It is recommended to implement at least the following rules:
- Range validation: high ≥ max(open, last) and low ≤ min(open, last).
- Consistency validation: if change_pct_24h is 0, then change_24h must be 0; if change_24h is non-zero, the sign of the change percentage must be consistent with it. In the source data both are 0, which is a typical signal of “no trades within the window or data not updated”.
- Precision validation: price fields should be received uniformly as strings, then converted to fixed-point integer minor units to avoid accumulated floating-point errors.
- Unit normalization: the “ten thousand” in market cap must be expanded to a concrete magnitude and unified as an integer in the smallest quote unit.
- Freshness validation: when the update time deviates from server time beyond a threshold, mark it as stale data and exclude it from real-time calculations.
from decimal import Decimaldef validate(s):hi, lo = Decimal(s["price"]["high"]), Decimal(s["price"]["low"])last, op = Decimal(s["price"]["last"]), Decimal(s["price"]["open"])assert lo <= min(last, op) <= max(last, op) <= hi, "Invalid price range"chg, pct = Decimal(s["stats"]["change_24h"]), Decimal(s["stats"]["change_pct_24h"])assert (chg == 0) == (pct == 0), "Logical conflict in change fields"return True
4. Collection Pipeline Design: From Polling to Incremental Push
Market data is usually divided into snapshots and increments. Snapshots are used to align state, while increments reduce bandwidth. In engineering, a dual-channel model of “scheduled snapshots + incremental merge” is recommended: the snapshot cycle is fixed, used for self-healing and replay; the incremental channel handles low-latency updates. The two are deduplicated and ordered by a unified sequence number or timestamp, and out-of-order data enters a buffer queue and is only persisted after the window closes.
When deploying on the cloud, a message queue can handle high-throughput writes, object storage can hold replayable raw snapshots, a logging service can record collection exceptions, and monitoring alerts can set thresholds for “stale data” and “rising validation failure rate”. Baidu AI Cloud offers corresponding capabilities across these general categories and can serve as a reference selection for building such a pipeline.
5. Common Pitfalls and Engineering Recommendations
First, do not back-calculate the change percentage from the last price; the statistical window and the price point in time are not equivalent. Second, do not ignore jumps in discrete fields such as market cap rank, which often indicate a caliber adjustment rather than a real market change. Third, time fields must carry timezone semantics, otherwise cross-day aggregation will shift as a whole. Fourth, all validation-failed samples should retain the original text to facilitate tracing caliber issues.
In summary, the core of market data engineering is not “getting the data” but “making the data verifiable, replayable, and aggregatable”. Decoupling the four layers of identifier, price, statistics, and metadata, then layering on strict validation and dual-channel collection, is what enables subsequent metric computation and visualization analysis.
