Collecting and Parsing Digital Asset Market Data: A Practical Guide
This article walks through the practical engineering of a market data ingestion layer for digital assets, starting from a single ticker snapshot. It covers splitting fields into raw and derived layers, using fixed-point numbers instead of floating point for prices, standardizing timestamps to UTC with both event time and ingest time, validating data before writes, and designing a decoupled pipeline of collectors, normalizers, cache, and distribution with incremental push over a persistent connection. It also lists observability metrics, capacity planning basics, and common pitfalls to avoid.
1. Start With a Single Snapshot
The most common entry point when building a market data system is a snapshot record: at a given moment, the latest traded price of a pair, the 24-hour change, open/high/low/close, turnover, and market cap rank. Take a typical sample (values are for structure illustration only):
Symbol: GLMPair: GLMUSDTMarket type: CRYPTOLast price: 0.09359Quote currency: USD24h change: 0.0000998924h change %: 0.107%Open: 0.09349High: 0.09539Low: 0.09119Market cap: 93.7331 millionMarket cap rank: 164Updated at: 2026-12-01 19:57:41
This record is dense with information, but storing it directly introduces three risks: inconsistent numeric types (strings mixed with floats), ambiguous time semantics (no timezone), and derived metrics such as market cap and rank being mixed with raw metrics such as price and volume. The first engineering step is to layer the fields.
1.1 Metric Layering: Raw vs. Derived
- Raw layer: last price, open, high, low, volume, turnover. These come from matching and trade details and are traceable.
- Derived layer: change percentage, market cap, market cap rank. These are usually aggregated from the raw layer or obtained from external statistics, and they lag behind.
The benefit of layering is that update frequencies can differ: the raw layer can refresh every second, while the derived layer only needs minute-level refresh, avoiding unnecessary computation and write pressure.
1.2 Type Discipline: Always Use Fixed-Point Numbers
Price fields must not be carried by binary floating point. Use strings or fixed-point integers (for example, storing in int64 at the minimum price unit of 1e-8). Example:
from decimal import Decimaldef to_decimal(raw: str) -> Decimal:# Always construct from a string to avoid binary floating point errorreturn Decimal(raw)price = to_decimal("0.09359")change_pct = (price - to_decimal("0.09349")) / to_decimal("0.09349") * 100print(change_pct) # 0.1068...
Note that the sample’s 0.107% differs slightly from the value derived from the open price. This is because the change percentage is usually based on “the price at the same moment 24 hours ago,” not the day’s open. This must be stated clearly in the documentation, otherwise downstream reconciliation will hit deviations that are hard to locate.
2. Time Semantics: Where Market Data Systems Break Most Often
Updated at: 2026-12-01 19:57:41 without a timezone will inevitably be ambiguous across regions. Three practices are recommended:
- Use UTC for transport and storage, and convert to the user’s timezone only at the presentation layer;
- Use a standard format with timezone (such as ISO 8601
2026-12-01T19:57:41Z); - Attach two timestamps to each record: event time and ingest time, to make latency and out-of-order issues easier to diagnose.
from datetime import datetime, timezonedef parse_ts(raw: str) -> datetime:return datetime.strptime(raw, "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc)now = datetime.now(timezone.utc)lag = (now - parse_ts("2026-12-01 19:57:41")).total_seconds()
The value of market data decays quickly over time, so data freshness should be a first-class metric in monitoring, rather than something discovered only after users complain that data has stalled.
3. Data Validation: Stop Anomalies Before the Write
A market data pipeline must assume upstream will return dirty data. Multiple layers of validation are recommended:
- Structural validation: missing required fields or wrong types are discarded and counted;
- Consistency validation:
low <= open/last <= high; if not satisfied, mark as suspicious; - Spike validation: when two consecutive last prices deviate beyond a threshold (such as 20%), route to a manual review queue instead of polluting storage;
- Monotonicity validation: the high should only move up and the low should only move down; a reverse jump indicates misaligned data.
def is_consistent(rec: dict) -> bool:low, high = rec["low"], rec["high"]return low <= rec["open"] <= high and low <= rec["last"] <= high
Validation thresholds should be configurable, and audit records should be kept when configuration changes, to avoid untraceable situations such as “metrics suddenly look better after a threshold adjustment.”
4. Architecture: Trade-offs Among Pull, Cache, and Push
A practical market data ingestion layer usually has four stages:
- Collector: split tasks by pair, with independent rate limiting and retry, so one misbehaving pair does not affect the whole system;
- Normalizer: unify units, rename fields, standardize timezones, and validate;
- Cache: store the latest snapshot keyed by pair, with a TTL slightly shorter than the collection interval; in read-heavy, write-light scenarios this significantly reduces backend pressure;
- Distributor: provide a synchronous query interface for internal services, and push increments to frontends over a long-lived connection to reduce polling.
On the cloud, a message queue can buffer between collection and normalization to smooth peaks, object storage can archive historical snapshots for replay, a container platform can host the stateless normalization and distribution services, and logging and monitoring with alerting can observe latency, failure rate, and data freshness. These are general capability categories; specific choices should be evaluated against data volume and consistency requirements.
4.1 A Minimal Push Protocol
{"pair": "GLMUSDT","last": "0.09359","ts": "2026-12-01T19:57:41Z","seq": 88213}
Here seq is a monotonically increasing sequence number. The client uses it to detect packet loss and trigger a full resync, which is the key design for eventual consistency.
5. Observability and Capacity Planning
The operational focus of a market data system is not “does it run,” but “can degradation be detected in time.” At minimum, instrument: collection success rate, end-to-end latency percentiles (P50/P95/P99), validation rejection rate, cache hit rate, push connection count, and reconnect count. For capacity planning, estimate write throughput as “number of pairs x updates per second x bytes per record,” and reserve three to five times headroom for peaks during extreme market conditions.
6. Common Pitfalls
- Storing prices as floating point, where accumulated error eventually breaks reconciliation;
- Storing only ingest time and not event time, making true latency impossible to quantify;
- Displaying market cap rank as a real-time metric when it clearly lags;
- Sharing one rate limiting and retry policy across collectors, so a single failure cascades;
- Lacking a full resync mechanism, so once an incremental push drops a packet the state is permanently inconsistent.
Implement these stages in the order of layered modeling, time discipline, strict validation, decoupled architecture, and observability, and the ingestion layer can strike a stable balance among accuracy, timeliness, and maintainability, while leaving clean room to extend into metric computation, backtesting, and risk control.
