Digital Asset Market Data Collection and Parsing: A Practical Guide
This article walks through the engineering practice of collecting and parsing digital asset market ticker data. Starting from a single GLMUSDT snapshot, it covers field semantics and type modeling with Decimal and frozen dataclasses, the validation constraints that market data must satisfy, a three-layer collection pipeline built on caching, incremental fetching, and message broadcasting, anomaly detection and tiered alerting, storage trade-offs across hot, warm, and cold tiers, and key observability metrics for data quality. The approach is platform-agnostic and can run on self-hosted services or general cloud products.
1. Starting from a Single Ticker Snapshot
The raw material is a typical digital asset market record: symbol GLM, pair GLMUSDT, market type CRYPTO, quote currency USD, last price 0.09149, 24-hour change 0.002797 (3.153%), open price 0.08869, high 0.09368, low near 0.08759 at the lower edge of the 0.09759 range, market cap about 90.5415 million, rank 168, updated at 2026-11-24 14:28:28.
This record carries high information density, but treating it as “just a number” loses a large set of constraints. The sound engineering approach is to define field semantics first, then establish validation relationships between fields, and only then handle storage, computation, and display.
2. Field Semantics and Type Modeling
The first pitfall in market data is types. Price, change amount, and change percentage must be handled as floating-point or fixed-point decimals, never as integers. Market cap and rank are two entirely different dimensions: the former is a monetary amount, the latter is an ordinal.
from dataclasses import dataclassfrom decimal import Decimal@dataclass(frozen=True)class TickerSnapshot:symbol: str # Symbol code, e.g. GLMpair: str # Trading pair, e.g. GLMUSDTmarket_type: str # Market type, e.g. CRYPTOquote_currency: str # Quote currencylast: Decimal # Last pricechange_24h: Decimal # 24-hour change amountchange_pct_24h: Decimal# 24-hour change percentageopen_24h: Decimalhigh_24h: Decimallow_24h: Decimalmarket_cap: Decimal # Market caprank: int # Market cap rankupdated_at: str # Update timestamp
Using Decimal instead of binary floating point avoids tail differences when values like 0.09149 are accumulated or compared. Using frozen=True guarantees the snapshot is immutable, making it safe to share across threads or async tasks.
3. Constraints That Must Hold Between Fields
Market data comes with a set of “physical constraints” that form the first gate for data quality:
- Range constraint:
low_24h <= last <= high_24h, andlow_24h <= open_24h <= high_24h; - Consistency constraint:
change_24h ≈ last - open_24h. In this example, 0.09149 − 0.08869 = 0.00280, which matches 0.002797 within rounding error; - Ratio constraint:
change_pct_24h ≈ change_24h / open_24h × 100. This example gives about 3.15%, consistent with 3.153%; - Dimension constraint: market cap should be on the order of “unit price × circulating supply”, and rank must be a positive integer, unique within the same market;
- Freshness constraint: the gap between
updated_atand the current time should fall within an acceptable window; beyond it, the data is considered stale.
Writing these five as assertions lets you intercept dirty data right at the ingestion point:
def validate(t: TickerSnapshot) -> list[str]:errs = []if not (t.low_24h <= t.last <= t.high_24h):errs.append("last out of [low, high]")if abs((t.last - t.open_24h) - t.change_24h) > Decimal("0.0001"):errs.append("change mismatch")if t.rank <= 0:errs.append("invalid rank")return errs
4. Collection Pipeline: Polling, Incremental Fetching, and Caching
Market data changes at high frequency, and the collection strategy directly determines the balance between cost and real-time performance. A common design has three layers:
- Edge cache layer: cache the latest snapshot keyed by symbol, with a TTL slightly shorter than the data update cycle, to avoid repeated upstream calls within the same second;
- Incremental fetch layer: request only the set of symbols that changed, and merge deltas using a version number or timestamp to reduce bandwidth and parsing overhead;
- Persistence and broadcast layer: distribute change events to downstream computation and alerting modules through a message queue, achieving “collect once, consume in many places”.
Illustrative scheduling logic:
import timedef poll_loop(fetcher, cache, sink, interval=5.0):while True:batch = fetcher.diff(cache.keys())for raw in batch:snap = parse(raw)if validate(snap):continuecache.put(snap.symbol, snap)sink.publish(snap)time.sleep(interval)
The key here is not the code itself but three design trade-offs: the polling interval must be larger than the data update granularity; failures must be retryable and idempotent; and downstream consumers must tolerate out-of-order and duplicate events.
5. Anomaly Detection and Alerting
In real operation, the most dangerous situation is not “no data” but “data that looks normal”. At least four types of detection are recommended:
- Jump detection: flag for confirmation when the change between two adjacent snapshots exceeds a threshold (e.g. more than 5% in a single cycle);
- Stall detection: the last price and update timestamp stay unchanged for a long time, possibly indicating upstream delay;
- Range break: the last price moves outside the day’s high-low range, usually caused by inconsistent aggregation;
- Rank drift: a large short-term move in market cap rank needs cross-validation against the market cap change.
For alerting, tiering is recommended: issues that can be auto-corrected (such as rounding differences) are only logged; issues that affect computation results (such as range breaks) enter a manual review queue; issues that affect public display trigger immediate notifications. Combined with the general capabilities of logging and monitoring services, this forms a closed loop of “collect, validate, alert, review”.
6. Storage and Query Trade-offs
Market data has two typical consumption patterns: querying the latest value by symbol, and querying historical series by time range. The former suits key-value storage, while the latter suits time-series or columnar storage. A common engineering combination is: hot data kept in an in-memory cache for real-time display, warm data written to a time-series database for range statistics, and cold data archived to object storage to control cost.
It is worth emphasizing that market cap and rank are “derived metrics” that change with overall market movements. They must therefore be stored and updated separately from the price snapshot; otherwise, fields within the same snapshot can end up with inconsistent definitions.
7. Observability and Quality Metrics
Define a small but critical set of quality metrics for the data pipeline: validation failure rate, average latency, stale data ratio, and alert acknowledgement time. These metrics reflect whether the data is trustworthy better than “is the endpoint available”. If the collection and computation modules are deployed on a container platform with logging services, these metrics can be exposed uniformly to the monitoring and alerting system, enabling fine-grained observation by symbol and by data source.
8. Summary
A seemingly simple ticker snapshot actually involves four engineering problems: types, constraints, freshness, and definitions. Modeling fields clearly, writing constraints as assertions, building collection around incremental fetching and caching, and turning anomalies into tiered alerts are what keep market data trustworthy at both the display and computation layers. This approach depends on no specific platform and can be applied directly to self-hosted services or to a combination of general cloud products on Baidu AI Cloud.
