Market Data Collection and Parsing for Digital Assets: A Practical Guide
This article walks through the engineering practice of collecting and parsing digital asset market data. Using a typical market snapshot as a sample, it defines a reusable three-layer data model, explains how to handle precision and timestamp pitfalls, and outlines a four-stage pipeline covering collection, cleaning, aggregation, and serving. It also covers storage selection, cloud deployment, and the monitoring metrics needed to catch silent failures. The core takeaway is that model abstraction, precision control, and observability matter more than API integration.
1. Introduction: Why Market Data Engineering Is Harder Than It Looks
In digital asset trading, quantitative research, and risk control systems, market data is the most fundamental layer and also the most easily underestimated. Many teams start by storing the “latest price” in a single floating-point value. Once they connect multiple data sources and trading pairs, problems such as precision loss, inconsistent timestamps, and missing fields begin to contaminate downstream calculations.
This article uses a typical market snapshot as a sample, abstracts it into a general-purpose data model, and lays out a complete engineering approach to collection, cleaning, storage, and monitoring. The sample fields include: asset code, trading pair, market type, asset name, latest price, quote currency, 24-hour price change, 24-hour change percentage, open price, high price, low price, market cap, market cap rank, and update time.
2. A Unified Data Model: Turning Snapshots into Reusable Structures
Field names vary widely across data sources, so the first step must be field standardization. It helps to split market data into three layers:
{"symbol": {"code": "SOL", "pair": "SOLUSDT", "market": "CRYPTO"},"quote": {"price": 71.58, "currency": "USD", "open": 71.53,"high": 78.38, "low": 70.02},"stats": {"change_24h": 0.04994, "change_pct_24h": 0.070,"market_cap": 42540000000, "rank": 7},"meta": {"source": "feed_a", "ts": "2026-11-24T13:24:38Z"}}
The benefit is clear: when you add a new data source, you only need to write an adapter that maps external fields to the internal model. Downstream logic stays untouched.
3. Precision and Time: Two of the Most Overlooked Pitfalls
Precision. Prices and price changes must never be accumulated or compared directly as binary floating-point values. Numbers like 0.04994 accumulate rounding errors after repeated operations. Two common approaches are fixed-point numbers (integers with an agreed number of decimal places) and high-precision decimal types. Example:
from decimal import Decimalprice = Decimal("71.58")change = Decimal("0.04994")assert price - change == Decimal("71.53006")
Time. Update timestamps must be normalized to timezone-aware UTC. When writing to storage, keep both the “collection time” and the “data source time” so you can compute latency. If the gap between the two keeps widening, the pipeline has a backlog.
4. Pipeline Design: Collection, Cleaning, and Aggregation
Split the pipeline into four stages that can scale independently:
- Collection layer: Poll on a schedule or subscribe to push feeds, apply rate limiting and retries, and send failures to a backoff queue.
- Cleaning layer: Validate required fields, check that prices are positive, ensure the high is not below the low, and confirm that the change percentage and change amount are consistent.
- Aggregation layer: Build minute/hour candlesticks and compute averages, extremes, and volatility.
- Serving layer: Expose query APIs and push channels to business systems; hot data can live in an in-memory cache.
Example cleaning rule:
def valid(q):return (q["high"] >= q["low"] > 0and abs((q["price"] - q["open"]) - q["change_24h"]) < 1e-6)
5. Storage Selection and Cloud Deployment
Choose storage by access pattern: key-value stores for high-frequency point lookups; time-series databases for time-based aggregation; object storage for archiving raw records; and message queues for decoupling across services. On Baidu AI Cloud, you can combine general-purpose capabilities such as object storage, message queues, container platforms, log services, and monitoring/alerting to separate collection from computation and enable elastic scaling.
6. Monitoring, Alerting, and Quality Metrics
Metrics you must monitor include collection latency, field missing rate, cleaning rejection rate, price jump magnitude, and data source availability. Silent failures such as “the latest price has not changed for a long time” need dedicated rules; otherwise they are easily mistaken for normal behavior.
7. Conclusion
The core of market data engineering is not API integration but model abstraction, precision control, and observability. Get these three right, and onboarding any new data source becomes incremental work.
