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, starting from a typical ticker snapshot. It explains how to group fields by semantics, define validation rules for data quality, design a layered collection pipeline, manage freshness and precision, and build observability with graceful degradation. Readers can use these practices to implement a minimal viable market data service in their own systems.
1. Start with Data Modeling from a Single Ticker Snapshot
The source material is a typical digital asset market record containing the asset code, trading pair, market type, asset name, latest traded price, quote currency, 24-hour price change and change percentage, open price, high price, low price, market cap, market cap ranking, and data update time. This structure is extremely common in market data systems and is essentially a combination of “timestamp + multi-dimensional quotes for an instrument.”
Before writing any code, the first step is not parsing but abstraction. It is recommended to divide the fields into four groups:
- Instrument identification group: asset code, trading pair, market type, asset name. Used to uniquely determine “who, in which market, and quoted in what currency.”
- Price group: latest price, open price, high price, low price. Describes the price distribution over a statistical period.
- Derived metrics group: 24-hour change, change percentage, market cap, market cap ranking. These are usually aggregated and calculated from raw data.
- Metadata group: quote currency, update time. Determines the comparability and timeliness of the data.
The value of this grouping is that the collection layer only cares about the identification and price groups, the computation layer handles derived metrics, and the presentation layer consumes metadata. After layering, replacing a data source at any stage will not trigger changes across the entire pipeline.
2. Field Semantics and Validation Rules
The most common failure in market data is not “unable to fetch” but “fetched but untrustworthy.” Therefore, validation rules must be established before storing data. The following is a set of general constraints that can be directly implemented:
- Prices non-negative and finite: latest price, open price, high price, and low price must be finite values greater than 0, with nulls and infinities explicitly excluded.
- Range consistency: low price ≤ latest price ≤ high price, and low price ≤ open price ≤ high price. Records violating this constraint should be flagged as suspicious.
- Derived metric consistency: the change percentage should be consistent with (latest price − open price) / open price within an allowed floating-point error; the change amount should be approximately equal to latest price − open price. If the deviation exceeds a threshold, the upstream calculation method may have changed.
- Time monotonicity: the update time for the same instrument should be monotonically increasing; a rollback usually indicates cache replay or a data source switch.
- Units of ranking and market cap: market cap and ranking are aggregated metrics, and their units and statistical scope must be clearly defined to avoid unit confusion when stitching data across sources.
Illustrative validation code (Python):
import mathfrom dataclasses import dataclass@dataclassclass TickerSnapshot:symbol: strpair: strmarket: strlast: floatopen: floathigh: floatlow: floatchange_pct: floatmarket_cap: floatrank: intupdated_at: strdef validate(s: TickerSnapshot, eps: float = 1e-6) -> list[str]:errs = []prices = [s.last, s.open, s.high, s.low]if any((not math.isfinite(p)) or p <= 0 for p in prices):errs.append("price must be positive and finite")if not (s.low <= s.last <= s.high and s.low <= s.open <= s.high):errs.append("price out of [low, high] range")expected = (s.last - s.open) / s.open * 100if abs(expected - s.change_pct) > 0.05:errs.append("change_pct inconsistent with open/last")return errs
3. Layered Design of the Collection Pipeline
A robust market data collection system is typically divided into four layers:
- Ingestion layer: responsible for scheduled or incremental pulling, handling timeouts, retries, and rate limiting. Exponential backoff retries are recommended, with a circuit breaker threshold for consecutive failures.
- Parsing and normalization layer: maps fields from different sources to a unified model, standardizing numeric precision, time formats, and currency units. Timestamps in raw records should be unified into a standard format with time zones to avoid errors in cross-time-zone comparisons.
- Validation and enrichment layer: executes the rules from the previous section, supplements derived metrics, and writes data quality labels.
- Storage and serving layer: time-series data is suitable for time-series databases or columnar storage, partitioned by instrument and time; data is distributed externally via APIs or message queues.
The key design principle is idempotency: repeated delivery at the same point in time should not produce duplicate records. (instrument identifier, update time) can be used as the idempotency key.
4. Timeliness, Precision, and Cost Control
The value of market data decays rapidly over time, so timeliness management is a core engineering problem:
- Freshness determination: set a maximum acceptable delay for each type of data; overdue data is marked as stale on the presentation end to avoid misleading decisions.
- Precision strategy: price fields retain sufficient decimal places, and high-precision types or fixed-point numbers are used when calculating change percentages to reduce cumulative errors.
- Hot/cold tiering: recent data is placed in high-performance storage, while historical data is moved to low-cost object storage, with partition pruning to control query costs.
- Sampling and aggregation: high-frequency data is pre-aggregated at minute and hour levels, balancing query performance and storage overhead.
If a cloud-based approach is adopted, a combination of general-purpose capabilities can be used: message queues for peak shaving and decoupling, object storage for historical archiving, container platforms for running collection and computation tasks, and logging services with monitoring and alerting for observability. Similar general-purpose capabilities offered by vendors such as Baidu AI Cloud can be candidates; selection should be based on compatibility, portability, and cost models, avoiding strong coupling to a single interface.
5. Observability and Exception Handling
It is recommended to monitor at least the following metrics: collection success rate, end-to-end latency, validation failure rate, field missing rate, number of price range violations, and number of update time rollbacks. Retain raw messages for validation failure samples to facilitate tracing upstream calculation changes.
Exception handling can be divided into three levels: a single anomaly enters an isolation queue and triggers an alert; batch anomalies trigger data source degradation and switch to a backup source; persistent anomalies pause external distribution of the instrument to prevent polluting downstream computations.
6. Summary
A seemingly simple ticker snapshot, when expanded, involves multiple engineering stages including data modeling, quality validation, layered collection, timeliness and cost management, and observability. Grouping fields by semantics, moving validation forward, and making the pipeline idempotent and degradable are key to building a reliable market data service. Readers can implement a minimal viable solution in their own systems based on this, and then gradually add aggregation, replay, and multi-source comparison capabilities.
