Market Data Pipeline Design for Digital Assets: Collection, Parsing, and Data Quality
This article presents a practical methodology for building a digital asset market data pipeline, covering field semantics, timestamp and freshness handling, anomaly detection, collection architecture, layered storage, and observability. Using a sample market snapshot as a reference, it explains how to define consistent field meanings, validate price ranges and change calculations, deduplicate with idempotent writes, and manage cursors for incremental sync. The goal is to help engineering teams avoid common pitfalls such as inconsistent time zones, drifting definitions, and stale data, and to build a reliable data foundation for quantitative research, risk monitoring, and dashboards.
1. Introduction: Why Market Data Pipelines Deserve Attention
In quantitative research, risk monitoring, and data visualization, market data is the most fundamental and most easily underestimated component. Many teams focus on models and strategies while overlooking upstream data quality issues: inconsistent timestamps, ambiguous field meanings, missing values and outliers, and duplicate fetches that cause definition drift. The end result is a mismatch between backtests and live trading, reports that do not reconcile, and extremely high troubleshooting costs.
This article starts from a typical digital asset market snapshot and abstracts a general methodology for market data processing. It does not involve any specific trading platform or third-party product. All values are used only as examples of field structure, with the focus on engineering implementation and data governance.
Here are the dimensions of information contained in the snapshot:
{"symbol": "GLM","pair": "GLMUSDT","market_type": "CRYPTO","last_price": 0.09359,"quote_currency": "USD","change_24h_abs": 0.00009989,"change_24h_pct": 0.107,"open_price": 0.09349,"high_price": 0.09539,"low_price": 0.09119,"market_cap": 93733100,"rank": 164,"update_time": "2026-12-01 19:58:31"}
2. Field Semantics: Define the Rules First
The first step in data governance is not writing code, but writing documentation. Every field must have a clear, unambiguous definition; otherwise, all downstream statistics will be distorted.
- Trading pair and quote currency:
pairrepresents the trading pair combination, andquote_currencyrepresents the pricing unit. The two must stay consistent; mixing them leads to incorrect price dimensions. - Latest price and open price:
last_priceis the traded price at the sampling moment, whileopen_priceis the starting price of the statistical period. Their difference does not equal the change percentage, because period boundaries may be defined differently. - 24-hour absolute and percentage change: the absolute value and the percentage are two expressions of the same fact. In theory, they should satisfy
change_pct ≈ change_abs / open_price × 100. Verifying with the sample data: 0.00009989 / 0.09349 × 100 ≈ 0.1068%, which is essentially consistent with the given 0.107%, indicating that the definitions are self-consistent. - High and low prices: it is necessary to validate
low ≤ open, last ≤ high; otherwise, the data is contaminated. - Market cap and rank: market cap is usually derived from circulating supply multiplied by price. It is a derived metric, and circulating supply definitions vary significantly across sources, so it should not be used as a strongly consistent field.
- Update time: this is the most easily overlooked yet most critical field, as it determines the “freshness” of the data.
3. Timestamps and Freshness: The First Gate of the Pipeline
The value of market data decays rapidly over time, so time handling must be rigorous.
First, unify time zones and formats. Raw timestamps often lack time zone information. Before storage, they should be converted to a standard format with time zones, for example stored in UTC and rendered in the user’s time zone at the presentation layer.
Second, define freshness thresholds. Different thresholds can be set based on asset volatility, for example 5 seconds for mainstream assets and 30 seconds for long-tail assets. Anything beyond the threshold is marked as stale and is prohibited from participating in real-time calculations.
Third, handle out-of-order and duplicate data. In distributed collection environments, arrival order is not guaranteed to match generation order. In engineering, a common approach is an “event time + watermark” mechanism, or simply using (symbol, update_time) as an idempotency key for deduplicated writes.
def is_fresh(update_time, now, ttl_seconds=30):return (now - update_time).total_seconds() <= ttl_secondsdef normalize(record):low, high = record["low_price"], record["high_price"]if not (low <= record["open_price"] <= high):raise ValueError("Price range is contradictory")if low > record["last_price"] or record["last_price"] > high:raise ValueError("Latest price is out of bounds")return record
4. Anomaly Detection and Data Quality Validation
Common market data anomalies fall into four categories, each requiring a corresponding handling strategy:
- Null values or missing fields: missing critical fields (price, time, trading pair) should be discarded directly, counted, and alerted; non-critical fields (rank, market cap) may be empty.
- Out-of-range values: prices must be positive, and change percentages should be constrained to a reasonable range; values beyond that are considered suspicious.
- Logical contradictions: for example, a high price lower than the low price, or an absolute change that contradicts the percentage change.
- Long silence: a trading pair with no updates for a long time may indicate a problem on the data source side and needs independent monitoring.
It is recommended to attach a quality label to each record rather than simply discarding it. This preserves traceability and makes it easier to produce data quality reports later.
5. Collection Architecture: Polling, Push, and Incremental Sync
In engineering, there are usually three modes, which can be combined by scenario:
- Scheduled polling: simple to implement, suitable for low-frequency assets and offline analysis. Reasonable jitter should be configured to avoid all tasks sending requests in the same second.
- Long-lived connection push: low latency, suitable for real-time dashboards and risk control, but it requires handling reconnection and heartbeats.
- Incremental sync: uses the update time as a cursor and fetches only the changed portion, significantly reducing bandwidth and storage pressure.
A general incremental fetch skeleton is as follows:
cursor = load_cursor() # The timestamp of the last successful processingbatch = fetch_since(cursor) # Fetch incremental datafor item in batch:item = normalize(item)if is_fresh(item["update_time"], now):sink.write(item) # Idempotent writecursor = batch[-1]["update_time"] if batch else cursorsave_cursor(cursor)
The key lies in cursor persistence and idempotent writes. Together, they ensure that no duplicate data is produced under “at-least-once” delivery semantics.
6. Storage and Computation: A Layered Design
A three-layer structure is recommended:
- Raw layer: retains original messages without any modification, used for retrospection and troubleshooting.
- Cleaned layer: structured and standardized data with quality labels, used for analysis and backtesting.
- Aggregated layer: pre-aggregated candlestick charts and statistical metrics by minute, hour, and day, used for dashboard and report queries.
When deploying on the cloud, it is possible to combine object storage for raw files, a message queue for peak shaving and decoupling, a container platform for collection and cleaning tasks, and logging and monitoring services for observability. Such general capabilities are widely offered in product categories such as Baidu AI Cloud, and teams can select flexibly according to their own scale, avoiding reinventing infrastructure.
7. Observability and Alerting
A data pipeline must be monitored like an online service. Core metrics include collection success rate, end-to-end latency, data volume per unit time, quality validation failure rate, and cursor lag duration. Alerts should be tiered: increased latency is a reminder, while data interruption is urgent. Field-level statistical snapshots should also be retained to quickly determine whether the issue is on the data source side or in internal logic.
8. Common Pitfalls
- Directly multiplying the latest price by a fixed circulating supply to estimate market cap, ignoring definition differences and causing distorted cross-sectional comparisons.
- Using timestamps without time zones for cross-market alignment, producing deviations of several hours.
- Treating change percentages as additive metrics for multi-period accumulation; the correct approach is chained multiplication.
- Monitoring only whether the service is alive, without monitoring whether the data is fresh.
9. Conclusion
The complexity of a market data pipeline lies not in any single technical point, but in the systematic design of definition consistency, time semantics, and quality constraints. By clearly defining field semantics, enforcing freshness, classifying and handling anomalies, and making cursors and idempotency solid, combined with general cloud capabilities for storage, queues, containers, and monitoring, you can build a trustworthy, scalable, and easy-to-operate data pipeline that provides a stable foundation for upstream analysis and decision-making.
