Building a Market Data Pipeline for Digital Assets: Collection and Parsing Practices
This article presents a reusable approach to collecting and parsing digital asset market data. Starting from a public quote sample, it defines a minimal field model, explains how to align field semantics such as trading pairs, price ranges, change metrics, market cap, and timestamps, and then covers pipeline design across collection, validation, storage, and monitoring. It also includes pseudocode for the collection and validation loops, a troubleshooting checklist, and guidance on building a reliable data foundation for trading, quantitative research, and risk control systems.
1. Introduction: Why Market Data Pipelines Need Engineering
In digital asset trading, quantitative research, and risk control systems, market data is the most fundamental and most easily underestimated component. Many teams focus their energy on strategy and matching logic, yet repeatedly stumble over a seemingly simple set of quote fields: inconsistent timestamp time zones, mismatched definitions of price change, confusion between market cap and circulating supply, and data gaps caused by API rate limits. Using a public quote sample as a starting point, this article abstracts a general-purpose field model and provides a reusable collection and parsing approach.
The key fields in the sample include: symbol, trading pair, market type, latest price, quote currency, 24-hour price change and percentage change, open price, high price, low price, market cap, market cap ranking, and data update time. Together, these fields form the minimal complete set for a market snapshot, and any in-house pipeline should be able to carry them without loss.
2. Field Semantics and Definition Alignment
The first step in engineering is not writing code, but documenting definitions clearly.
- Symbol and trading pair: The symbol identifies the asset itself, the trading pair describes the “base asset/quote asset” relationship, and the market type distinguishes different matching mechanisms such as spot and derivatives. These three must not be used interchangeably; otherwise, primary key conflicts will arise when aggregating data from multiple sources.
- Price family: The latest price is the trade or best quote at the snapshot moment. The open, high, and low prices form interval statistics and must be bound to an explicit statistical window (such as a rolling 24 hours). Different window boundaries will directly cause different values for the same symbol.
- Change definitions: The price change is an absolute difference, while the percentage change is a relative ratio. It must be clear whether the denominator is the open price or the previous day’s close; the two can differ significantly during sharp volatility.
- Market cap and ranking: Market cap is usually the price multiplied by circulating supply, and ranking is the result of sorting across the entire market. Ranking is a high-frequency changing field, unsuitable as a persistence primary key and only suitable as a display and filtering dimension.
- Time fields: The update time is the sole basis for data freshness. It must be stored uniformly as timezone-aware UTC time, with localization handled at the presentation layer.
It is recommended to maintain a field dictionary that fixes the type, unit, precision, definition, and update frequency of each field, serving as a contract for cross-team collaboration.
3. Collection Layer Design: Stability First
The core goals of the collection layer are “no missing points, no duplicates, and traceability.”
- Combine incremental and full loads: At startup, use a full snapshot to establish a baseline; during runtime, pull changed fields incrementally, and periodically perform full alignment to correct drift.
- Rate limiting and backoff: For requests that return rate limits or time out, use exponential backoff retries, and set a maximum retry count and circuit breaker threshold to avoid cascading failures.
- Local buffering: Persist to an in-memory queue or local log before processing, ensuring the process can resume from the breakpoint after a restart.
- Multi-source redundancy: Keep two independent data sources for critical symbols, cross-validate price deviations, and route to a manual review queue when the threshold is exceeded.
A schematic collection loop is shown below (pseudocode, expressing structure only):
while not shutdown:batch = fetch_snapshot(symbols, cursor)if batch is None: # rate limited or network errorsleep(backoff()); continuefor item in batch:rec = normalize(item) # unify fields and unitsif validate(rec):buffer.append(rec) # buffer first, persist latercursor = batch.next_cursorsleep(interval)
4. Cleaning and Validation: Keeping Dirty Data Out of Storage
Cleaning rules should be configurable and replayable. Common validations include:
- Type and range validation: Prices must be positive, percentage changes must be within a reasonable range, and market cap and ranking must be non-negative.
- Consistency validation: The high price must not be lower than the latest price and the open price, and the low price must not be higher than either; the price change and percentage change should be mutually consistent under a given definition.
- Time-series validation: The update time must be monotonically increasing; when a regression occurs, it is judged as out of order and placed in a separate quarantine area.
- Precision handling: When decimal places differ across sources, unify to a fixed precision to avoid floating-point accumulation errors; for monetary fields, fixed-point numbers or string storage are recommended.
Example:
def validate(r):if r.price <= 0: return Falseif not (r.low <= r.open <= r.high): return Falseif r.ts < last_ts: quarantine(r); return Falsereturn True
5. Storage and Query
Storage selection depends on the query pattern. Scenarios dominated by time-series queries are suited to time-series databases, partitioned by symbol and time; scenarios dominated by point lookups of the latest value can use key-value storage with caching. A “hot-warm-cold” tiering approach is recommended: the hot tier retains the most recent hours of raw-precision data, the warm tier retains minute-level aggregates, and the cold tier is archived to object storage for long-term retention. The partition key is recommended to be “symbol + time bucket,” which can significantly narrow the scan range.
6. Monitoring and Alerting
Monitoring should cover data quality, not just system liveness: data latency (the difference between the current time and the latest update time), missing rate, validation failure rate, and cross-source price deviation. When any metric exceeds its bound, an alert is triggered, attached with the cursor position of the last successful run for quick localization. Log services and monitoring/alerting capabilities can serve as general infrastructure to carry these metrics.
7. Common Issues and Troubleshooting Checklist
- Values do not match: First confirm the statistical window and change definition, then check the time zone.
- Data gaps: Check whether rate-limit backoff is effective and whether the cursor is advancing.
- Duplicate writes: Construct an idempotency key with “symbol + timestamp + data source.”
- Ranking jumps: This is normal behavior; do not use it as a business primary key.
8. Conclusion
The value of a market data pipeline lies not in showing off, but in clear definitions, observable pipelines, and recoverable failures. Making the field dictionary, validation rules, backoff strategy, and monitoring metrics solid provides a reliable foundation for subsequent strategy and risk control. For elastic scaling, container platforms and message queues can be combined to decouple collection and parsing, completing deployment and elastic scaling on general cloud infrastructure such as Baidu AI Cloud.
