Collecting and Parsing Digital Asset Market Data: A Practical Guide
This article walks through the practical engineering of a digital asset market data pipeline, using a single ticker snapshot as the starting point. It explains how to model the record with precise decimal types, why derived fields should not be stored as facts, and how to validate incoming data against range, non-negative, consistency, and freshness rules. It also covers aligning multiple sources on a unified UTC timeline, resampling into fixed windows, and designing a layered storage and query architecture across raw, detail, and metric layers. Finally, it outlines observability metrics and tiered alerting needed to keep the service reliable and consistent when data sources switch.
1. Start With the Structure of a Single Ticker Snapshot
When building a market data application, the first step is not writing code but clarifying what a single market record actually contains. Take a public snapshot captured at a given moment as an example; its information can be broken down into the following categories:
- Identity: asset symbol, trading pair identifier, market type (e.g., crypto asset market);
- Price: latest traded price, open, high, low;
- Derived: 24-hour change amount, change percentage;
- Scale: market capitalization, market cap ranking;
- Metadata: quote currency, data update time.
The values in this snapshot look roughly like: last price 0.07991, open 0.07911, high 0.08381, low 0.07831, 24-hour change 0.0007991, change ratio 1.010%, market cap about 27.8983 million, market cap rank 455, update time 2026-11-24 17:07:29.
There is one easily overlooked engineering detail here: derived fields should not be stored as fact data. The change amount, change ratio, and market cap can all be computed from base fields. Once the upstream definition changes (for example, market cap is recalculated based on circulating supply), persisting derived values causes inconsistent definitions across historical data. The recommendation is to persist only “observable facts” and compute derived metrics in real time at the query layer or write them into a separate metrics table.
from dataclasses import dataclassfrom decimal import Decimal@dataclass(frozen=True)class TickerSnapshot:symbol: str # asset symbolpair: str # trading pairmarket_type: str # market typequote_currency: str # quote currencylast: Decimal # last priceopen: Decimal # open pricehigh: Decimal # high pricelow: Decimal # low pricets: str # data timestampdef change_ratio(self) -> Decimal:if self.open == 0:return Decimal(0)return (self.last - self.open) / self.open * 100
Using Decimal instead of a floating-point type is because price data is sensitive to precision; a decimal like 0.07991 accumulates error under binary floating point, which then gets amplified when aggregating over long time series.
2. Data Validation: Keep Dirty Data Out of the Service
The most common failure in a market data pipeline is not downtime but “silent bad data”. In the sample above, the high is 0.08381 and the low is 0.07831, and the last price 0.07991 falls within that range, which is the most basic validity constraint. In real engineering, at least four layers of validation are recommended:
- Range constraints: low ≤ last ≤ high, and low ≤ open ≤ high;
- Non-negative and zero-value constraints: price and market cap must be greater than zero; the change amount is allowed to be negative;
- Consistency check: recompute the change ratio from the last price and open price, compare it against the upstream-provided 1.010%, and flag as suspicious if the deviation exceeds a threshold;
- Freshness check: when the difference between the data timestamp and the service’s current time exceeds a tolerance window (e.g., a few minutes), mark it as stale and exclude it from real-time display.
def validate(s: TickerSnapshot, max_deviation=Decimal("0.05")) -> list[str]:errs = []if not (s.low <= s.last <= s.high):errs.append("last out of [low, high]")if not (s.low <= s.open <= s.high):errs.append("open out of [low, high]")if s.last <= 0 or s.high <= 0:errs.append("non-positive price")derived = (s.last - s.open) / s.open * 100 if s.open else Decimal(0)if abs(derived - Decimal("1.010")) > max_deviation:errs.append("change ratio inconsistent")return errs
Data that fails validation should not be discarded outright; it should go into a separate quarantine area and trigger an alert, making it easier to trace upstream definition changes.
3. Time Alignment and Multi-Source Fusion
Market data from a single source often has gaps, so engineering practice typically introduces multi-source collection followed by fusion. The difficulty is that different sources have different time bases and update frequencies: some push at fixed second-level intervals, while others update on a trade-driven basis. Directly concatenating two timelines produces conflicts where “two prices exist at the same moment”.
The recommended approach is to unify everything onto a UTC timeline, resample at fixed windows (e.g., 1 second or 1 minute), and clearly define the value strategy for each window:
- For price fields, take the last valid value within the window (last-value-carry-forward);
- For high/low, take the extreme values within the window;
- For volume fields, accumulate;
- Mark missing windows explicitly as empty rather than fabricating them with prior values.
SELECTdate_trunc('minute', ts_utc) AS bucket,last_value(price, ts_utc) AS last_price,max(high) AS high,min(low) AS low,count(*) AS sample_cntFROM ticker_rawWHERE ts_utc >= now() - interval '1 day'GROUP BY 1ORDER BY 1;
sample_cnt is a key auxiliary column for judging data quality: a sudden drop in sample count for a window usually indicates jitter in the collection pipeline rather than a real market change.
4. Layered Storage and Query Design
Market data is a typical “write-heavy, read-light, time-range scan” workload, which suits a layered design:
- Raw layer: append-only, no modification, retaining all fields and original timestamps for traceback and recomputation;
- Detail layer: validated and standardized minute-level data that serves most queries;
- Metrics layer: pre-aggregated daily/weekly statistics used for leaderboards, market cap rankings, and similar scenarios.
The partition key should be based directly on time, combined with the asset symbol as a secondary partition to avoid full-table scans. For metrics like market cap ranking that require global sorting, you can leverage the log service and monitoring/alerting capabilities of a general cloud service to handle collection and threshold notifications, offload computation to periodic batch jobs on a container platform, and use object storage for cold data archiving, forming a cost-controlled layered structure.
5. Observability and Alerting
A market data service must ship with a “data health” dashboard. Core metrics include collection success rate, end-to-end latency, validation failure rate, empty window ratio, and price jump count. Price jump detection is especially important: if the change ratio between two adjacent sampling points exceeds a set threshold (for example, far beyond the asset’s recent volatility range), you should suspect a data source anomaly first rather than displaying it externally.
For alert design, tiering is recommended: rising latency and more empty windows are informational level; a rising validation failure rate is warning level; and no data for several consecutive windows is critical level, requiring an automatic switch to a backup data source.
6. Summary
A seemingly simple ticker snapshot requires handling five areas to become a reliable service: precision, validation, time alignment, layered storage, and observability. The core principles are: store only facts, compute metrics in real time, never stay silent on anomalies, and always unify time. A market data pipeline built along this path can support both real-time display and historical traceback and statistical analysis, while keeping definitions consistent when switching data sources.
