Engineering Market Data Pipelines for Digital Assets
Market snapshots look simple, but they drive display, analytics, risk, and alerting. This article explains how to standardize fields, compute derived metrics, validate quality, and design collection, storage, and alert workflows so downstream systems stay consistent and auditable.
1. Why market data needs engineering
A market snapshot is more than a few numbers. Downstream systems use it for display, statistics, risk control, and alerts. If a timestamp is off by a minute, or a price is truncated, change calculations go wrong.
Teams often start by scraping page text. As more instruments are added, problems appear: inconsistent field names, different definitions of the same metric across sources, and missing values filled with zero.
Engineering has three goals:
- Define the meaning and unit of every field so the data has a single contract.
- Implement metric calculations as testable code, not as logic scattered in UI code.
- Add quality checks and exception flags so bad data is blocked or labeled before it reaches consumers.
2. Snapshot field structure
A typical snapshot includes:
- Identity: symbol, trading pair, market type, name. These uniquely identify an instrument. The quote currency of the pair must be explicit.
- Price: last, open, high, low. These describe the price range in the current period.
- Change: 24-hour change amount and change percent. These are derived from prices and can be computed by the system rather than trusted from the source.
- Size: market cap and rank. Cap is usually circulating supply times price. Rank needs a full cross-section at the same time and cannot be computed from one snapshot.
- Time: update time. It defines freshness and is the basis for later decisions.
On ingest, record unit, precision, and timezone for each field—quote currency, amount scale, and whether time is UTC—so the same number is not interpreted in different ways.
3. Core metric calculations
3.1 Change amount and change percent
Change amount is last price minus a base price, usually the period open or the previous close. Change percent is change amount divided by the base price, times 100.
Two rules: the base price must be greater than zero, or division is invalid. Keep enough precision in calculation; round only at display.
3.2 Amplitude
Amplitude is the range of prices in the period: (high − low) ÷ open × 100%. Change percent is start versus now; amplitude is the maximum swing during the period. Together they distinguish a one-way move from high volatility.
3.3 Example code
The following converts a snapshot into derived metrics and flags obvious anomalies. Sample values illustrate the logic only.
from dataclasses import dataclass@dataclassclass Snapshot:symbol: strlast_price: floatopen_price: floathigh: floatlow: floatdef derive_metrics(s: Snapshot) -> dict:"""Compute derived metrics from price fields and return a quality flag."""if s.open_price <= 0:raise ValueError(f"{s.symbol}: open price must be positive")change = s.last_price - s.open_pricechange_pct = change / s.open_price * 100amplitude_pct = (s.high - s.low) / s.open_price * 100# Last price should sit in the high-low range; otherwise snapshots may be out of syncin_range = s.low <= s.last_price <= s.highreturn {"change": round(change, 8),"change_pct": round(change_pct, 4),"amplitude_pct": round(amplitude_pct, 4),"flag": "ok" if in_range else "price_out_of_range",}if __name__ == "__main__":sample = Snapshot("EXAMPLE", last_price=1.00, open_price=0.99, high=1.02, low=0.98)print(derive_metrics(sample))
Anomalous data is flagged rather than dropped so consumers can refetch, degrade the display, or review manually.
4. Data quality checks
Quality issues fall into four groups:
- Freshness. If update time is too far from now, mark the snapshot stale instead of treating it as live.
- Completeness. Do not replace missing key fields with zero. Keep nulls and record why they are missing, or change percent can become extreme (for example −100%).
- Consistency. Last, high, and low must satisfy basic ordering. Flag violations and keep original values for audit.
- Jumps. A large move between samples may be an error or a real shock. Do not auto-drop; combine with volume and other signals.
Timestamps are easy to mishandle. Convert to UTC at collection and store ISO 8601. Convert to the user timezone only at display. Compare parsed time objects, not strings.
5. System architecture
A workable pipeline has five stages:
- Collection: pull snapshots on a schedule or event, and keep raw messages for replay and debugging.
- Cleaning: map fields, convert types, unify units, and run the checks above.
- Computation: derive metrics separately from cleaning so they can be tested independently.
- Storage: time-series or relational stores depending on access patterns. Partition high-frequency snapshots by time; pre-aggregate history if needed.
- Alerting: fire notifications from computed results, with dedup and rate limits.
Decouple collection and computation with a message queue. Log latency, success rate, and flags. Page operators when collection failure rate exceeds a threshold.
6. Alert design
Alerts are noisy if thresholds are too sensitive.
A practical policy includes:
- Severity tiers: hint, warning, and critical by change percent or amplitude, with different channels.
- Duration: fire only if the metric stays over the threshold for several samples, to filter single spikes.
- Cooldown: after an alert of a given severity for a symbol, do not repeat until cooldown ends.
- Quality first: if data is stale or flagged, alert on data quality, not on a fake market move.
Thresholds should be configurable and retuned with backtests. Historical data has quality issues too; backtest trust depends on cleaning.
7. Common mistakes
- Treating vendor-derived metrics as ground truth. Periods and base prices differ; recompute and log large gaps versus the source.
- Ignoring precision. Floating point introduces small errors; use decimal or fixed-point for money.
- Watching only one instrument. At scale, track coverage and delay distributions, not a single last price.
- Treating quotes as investment advice. They describe past prices and do not determine the future. Funding decisions need fuller information; the system should not be designed to push trades.
8. Summary
Engineering market data means turning simple numbers into a contract that is clear, testable, and traceable. Field semantics, testable metrics, quality flags, and tunable alerts are the four supports. With that design, mixed sources and formats stay stable and explainable.
