Engineering Crypto Market Data: Collection, Parsing, and Quality Control Practices
This article presents a practical engineering approach to collecting, modeling, validating, and serving crypto market data. Using a sample ticker record as a reference, it covers a stable data model with high-precision decimals, hard and soft validation rules for detecting missing fields, time drift, and logical conflicts, rolling-window metric calculations, layered storage with idempotent synchronization, service design with observability, and common pitfalls to avoid. Readers will learn how to turn display-oriented ticker records into trustworthy, unified, and traceable data pipelines for analytics and decision-making.
1. Introduction: Why Market Data Needs Engineering
In digital asset trading and quantitative analysis, market data is the most fundamental production material. A seemingly simple ticker record usually contains fields such as the trading pair identifier, latest price, open/high/low/close, trading volume, market cap, rank, and a data timestamp. For example, a sample record might show: pair GLMUSDT, market type CRYPTO, last price 0.09359 USD, 24-hour change 0, change percentage 0.000%, open 0.09359, high 0.09539, low 0.09119, market cap about USD 93.7331 million, market cap rank 164, and updated at 2026-12-01 19:52:38.
If these fields stay only at the “presentation layer,” their value is limited. Only after structured modeling, consistent definitions, and quality validation can they support downstream metric calculation, backtesting, and monitoring alerts. Using this type of ticker record as a sample, this article provides a practical engineering approach.
2. Field Modeling: Turning Display Data into Computable Structures
The first step is to define a stable data model. Fields can be divided into four categories:
- Identity fields: trading pair code and market type, used for partitioning and routing;
- Price fields: last price, open, high, and low;
- Statistics fields: 24-hour change amount, change percentage, market cap, and market cap rank;
- Metadata fields: data update time and source batch number.
Modeling must specify types and precision. Prices should use a high-precision decimal type rather than binary floating point to avoid accumulation errors. The change percentage should store both the “ratio value” and the “display string” to prevent values like 0.000% from losing precision during parsing. Timestamps should be normalized to timezone-aware UTC, with the presentation layer rendering them in the local timezone.
from dataclasses import dataclassfrom decimal import Decimalfrom datetime import datetime, timezone@dataclassclass TickerSnapshot:symbol: str # Trading pair, e.g., PAIRUSDTmarket_type: str # Market typelast: Decimal # Last priceopen: Decimal # Open pricehigh: Decimal # High pricelow: Decimal # Low pricechange_24h: Decimal # 24-hour change amountchange_pct: Decimal # Change percentage (ratio value)market_cap: Decimal # Market caprank: int # Market cap rankupdated_at: datetime # Update time (UTC)def normalize(self):self.updated_at = self.updated_at.astimezone(timezone.utc)return self
3. Data Quality Validation: Doubt the Data Before Using It
The three most common problems in market data are missing fields, time drift, and logical conflicts. Logical conflicts mean the open/high/low/last relationships do not hold—for example, the high is lower than the last price, or the low is higher than the open. Time drift means the update time is clearly behind the current time, causing distorted metrics.
It is recommended to implement “hard rules + soft rules” in the validation layer:
- Hard rules: prices must be positive; high ≥ open, last, and low; low ≤ open and last; rank must be a positive integer.
- Soft rules: the sign of the 24-hour change percentage must match the change amount; if the last price equals the open, the change amount should be 0 and the change percentage should be 0.000%. The sample record is exactly this kind of “flat” state.
- Freshness rules: when the difference between the update time and the current time exceeds a threshold, mark the record as stale and exclude it from real-time dashboards.
def validate(t: TickerSnapshot) -> list[str]:errs = []if t.last <= 0 or t.open <= 0:errs.append("Non-positive price")if not (t.high >= max(t.open, t.last, t.low)):errs.append("High price logical conflict")if not (t.low <= min(t.open, t.last, t.high)):errs.append("Low price logical conflict")if t.last == t.open and (t.change_24h != 0 or t.change_pct != 0):errs.append("Flat state inconsistent with change fields")return errs
4. Metric Calculation: From Snapshots to Trends
A single snapshot can only describe “this moment”; trends require a sequence. In engineering, a rolling window is usually retained to calculate mean, volatility, and relative strength. Consistent definitions matter: if the change percentage comes from a 24-hour window, all derived metrics should align to the same time window to avoid misjudgment from mixing different periods.
def rolling_stats(prices: list[Decimal], window: int = 24):if len(prices) < window:return Noneseg = prices[-window:]mean = sum(seg) / windowvar = sum((p - mean) ** 2 for p in seg) / windowreturn {"mean": mean, "std": var.sqrt()}
The combination of market cap and rank carries additional meaning: market cap reflects scale, while rank reflects relative position. When the price changes but the rank stays the same, the overall market is likely moving in sync. When the price falls but the rank rises, other assets may be declining faster. Such cross-checks are more informative than looking at price alone.
5. Storage and Synchronization: Layered Design with Hot-Cold Separation
A three-layer storage design is recommended: the raw layer stores immutable original payloads for traceability; the detail layer stores standardized snapshots partitioned by time and trading pair; the summary layer stores minute-level and hour-level aggregates for fast dashboard and alert queries. The raw layer can use object storage, the detail layer a columnar structure, and the summary layer a key-value or time-series structure.
Synchronization tasks must be idempotent. Using “trading pair + update time” as the idempotency key, repeated writes overwrite rather than append, preventing duplicates caused by retries.
-- Idempotent write exampleINSERT INTO ticker_detail (symbol, updated_at, last, change_pct, rank)VALUES (:symbol, :updated_at, :last, :change_pct, :rank)ON CONFLICT (symbol, updated_at) DO UPDATESET last = EXCLUDED.last,change_pct = EXCLUDED.change_pct,rank = EXCLUDED.rank;
6. Service Design and Observability
When exposing market data services, distinguish real-time APIs from historical APIs: the real-time API returns the latest snapshot with a data timestamp, while the historical API supports paginated retrieval by interval. All responses should carry the data time so consumers do not treat stale data as real-time.
For observability, monitor at least four metrics: collection success rate, data latency, validation failure rate, and field missing rate. Combined with logging and alerting, this helps detect quality degradation before it becomes severe. As data volume grows, a message queue can be introduced for peak shaving, and a container platform can host stateless collection and computation tasks for elastic scaling.
7. Common Pitfalls and Best Practices
- Do not calculate real-time metrics from stale data; always check freshness first;
- Do not compare prices across sources directly; unify pricing units and precision first;
- Do not ignore timezones; concatenating sequences across timezones creates gaps;
- Do not treat display strings as calculation inputs; complete type conversion during parsing;
- Do not omit traceability; a missing raw layer makes problems impossible to locate.
8. Conclusion
The value of market data lies not in “seeing numbers” but in “trustworthy numbers, consistent definitions, and traceable pipelines.” From field modeling, quality validation, and metric calculation to layered storage and service design, every step determines the reliability of upstream analysis. Starting with the flat sample record and progressively completing the engineering steps above, you can build a stable and scalable market data foundation that provides reliable input for subsequent analysis and decision-making.
