Digital Asset Market Data Collection and Parsing: A Practical Guide
This article walks through a practical approach to collecting and parsing digital asset market data, covering the three-layer data model, field semantics and consistency validation, the collection pipeline, storage selection and query optimization, exception handling and observability, and security and compliance. It includes sample snapshot data, validation code, and alerting rules to help turn a simple price snapshot into a verifiable, replayable, and monitorable data asset.
1. Start with a Single Market Snapshot
A raw sample can be abstracted into the following structure (field names are kept neutral):
{"symbol": "GLMUSDT","market_type": "CRYPTO","base_asset": "GLM","last_price": 0.09119,"quote_currency": "USD","change_24h": 0.002497,"change_pct_24h": 2.815,"open_24h": 0.0887,"high_24h": 0.09369,"low_24h": 0.0876,"market_cap": 91616500,"rank": 166,"updated_at": "2026-11-24 14:39:36"}
This record is information-dense. It carries price dimensions (last, open, high, and low), derived metrics (24-hour change amount and percentage), global dimensions (market cap and rank), and a time dimension (update timestamp). In engineering terms, it should be split into three layers:
- Raw layer: keep the original upstream payload with no trimming, so it can be traced back and replayed.
- Standardized layer: unify field naming, units, precision, and time zone, and convert display units such as “ten thousand” into integer minor currency units.
- Service layer: wide tables or time-series tables built for querying and aggregation, supporting scenarios like threshold alerts and change-percentage rankings.
2. Field Semantics and Consistency Validation
The most common problem with market data is not “failing to fetch it” but “fetching it with inconsistent meaning.” Strict validation is therefore required before writing to storage:
- Range validation:
low_24h <= min(open_24h, last_price) <= max(open_24h, last_price) <= high_24h. In the sample, the low is 0.0876 and the high is 0.09369, and the last price of 0.09119 falls within the range, so validation passes. - Derived consistency: the change amount should be roughly the last price minus the price 24 hours ago, and the change percentage should be roughly the change amount divided by the prior value. In the sample, 0.002497 / 0.0887 ≈ 2.815%, which matches the given value.
- Precision and rounding: price fields are best carried as fixed-point numbers or strings to avoid tail differences caused by binary floating point after repeated operations.
- Time semantics: make it explicit whether the update time is the data generation time or the fetch time, store everything in UTC, and display in the business time zone.
Sample validation code:
from decimal import Decimaldef validate(t):low, high = Decimal(t["low_24h"]), Decimal(t["high_24h"])last, open_ = Decimal(t["last_price"]), Decimal(t["open_24h"])assert low <= last <= high, "price out of range"assert low <= open_ <= high, "open price out of range"calc_pct = (Decimal(t["change_24h"]) / open_ * 100).quantize(Decimal("0.001"))assert abs(calc_pct - Decimal(str(t["change_pct_24h"]))) <= Decimal("0.01")return True
3. Designing the Collection Pipeline
A robust collection pipeline typically has five stages: scheduling, fetching, parsing, validation, and persistence. The scheduling layer triggers on a fixed interval, which should be shorter than the maximum data delay the business can accept. The fetching layer needs timeout, retry, and backoff strategies so that transient jitter does not amplify into an avalanche. The parsing layer should be fault-tolerant: when a field is missing, write a null value and mark it rather than discarding the whole record. The persistence layer should write the raw layer first and then the standardized layer to guarantee replayability.
For high-frequency scenarios, incremental merging can be done on the collection side: keep only the latest record for the same trading pair within a short window, then batch-write when the window closes. This reduces write pressure while preserving the extreme values within the window.
4. Storage Selection and Query Optimization
Market data has distinct read/write characteristics: writes are dense, and queries mostly filter by “trading pair + time range.” Options include:
- Time-series database: naturally suited to timeline writes and downsampling, good for minute-level and hour-level aggregation.
- Relational database: suited to dimensional data (trading pair metadata, market cap rankings) and low-frequency queries.
- Object storage: suited to archiving raw payloads, with low cost and easy offline traceback.
- Message queue: decouples collection from consumption, smooths peaks, and supports multiple downstream subscribers.
On Baidu AI Cloud, these capabilities can be carried by general product categories such as time-series databases, relational databases, object storage, and message queues, forming a closed loop together with log services and monitoring alerts.
5. Exception Handling and Observability
Four types of exceptions must be handled explicitly: missing fields, type mismatches, out-of-range values, and time inversion (new data with a timestamp earlier than data already stored). For time inversion, adopt a “time wins, reject older data” strategy and record the rejection reason.
Observability should cover three layers: business metrics (data freshness, validation failure rate, number of abnormal change-percentage records), system metrics (collection duration, write latency, queue backlog), and alerting rules (no data for several consecutive intervals, a spike in validation failure rate, price out of range). Sample rules:
alerts:- name: stale_dataexpr: freshness_seconds > 300severity: warning- name: validate_fail_spikeexpr: validate_fail_ratio > 0.05severity: critical
6. Security and Compliance
Market data itself is not highly sensitive, but collection credentials and API keys must be managed in a key management service and must never be hard-coded. When exposing query interfaces externally, apply rate limiting and authentication to prevent bulk pulling, and avoid printing full credentials in logs. When dealing with external data sources, comply with their terms of use and use the data only for internal analysis.
7. Implementation Checklist
- Define the three-layer data model and a field dictionary that specifies units, precision, and time zone.
- Implement range validation and derived consistency validation, with failed samples routed to an isolation table.
- Add timeout, retry, backoff, and incremental merging on the collection side.
- Choose a combination of time-series, relational, and object storage based on query patterns.
- Establish three categories of observability metrics: business, system, and alerting.
- Roll out the three essentials together: credential management, interface rate limiting, and log masking.
Following this process, a seemingly simple market snapshot can be turned into a verifiable, replayable, and monitorable data asset, providing a reliable foundation for downstream analysis and decision-making.
