Collecting and Parsing Crypto Market Data: A Practical Engineering Guide
This article walks through the engineering practice of collecting and parsing digital asset market data, using a single spot ticker record as the starting point. It breaks down field semantics and derived relationships, then presents a platform-agnostic collection layer, a layered validation strategy, cold-hot storage tiering with idempotent writes, and observability built around data freshness and completeness. Readers will find practical guidance, Python and SQL examples, common pitfalls, and the core methodology for keeping a market data pipeline trustworthy over long-term operation.
1. Reading Market Data Structure from a Single Ticker Record
A typical spot market ticker record usually carries several categories of information: instrument identifiers (symbol and trading pair), market type, quote currency, last traded price, 24-hour absolute and percentage change, open price, high, low, market cap and market cap rank, and the data update time. Take one record as an example: symbol GLM, pair GLMUSDT, market type CRYPTO, last price 0.09099 USD, 24-hour change 0.002297, change percentage 2.590%, open 0.0887, high 0.09369, low 0.0876, market cap about 91.6165 million USD, market cap rank 166, update time 2026-11-24 14:38:35.
This record is information-dense, but ingesting or displaying it directly leaves engineering risks behind. Below we first break down field semantics, then give a validation and persistence plan.
1.1 Field Semantics and Derived Relationships
- Trading pair and quote currency: a trading pair is formed by concatenating the base instrument and the quote asset, and the quote currency determines the price dimension. When aggregating across markets, you must unify dimensions first; otherwise you get dirty data that is “correct in magnitude but wrong in meaning.”
- Open, high, low, last: the open is the price at the start of the statistics window, the high and low are the extremes within the window, and the last is the traded price at the end of the window. The four should satisfy the containment relation
low <= open, last <= high. - Absolute and percentage change: the common definition is
change = last - open,change_pct = change / open. In this example0.09099 - 0.0887 = 0.00229, which matches the given 0.002297 within rounding error;0.002297 / 0.0887 ≈ 2.59%also matches. These “verifiable” fields are the best handle for data quality checks. - Market cap and rank: market cap is usually circulating supply multiplied by price, and rank is the ordinal obtained by sorting on market cap. Both are derived metrics whose update frequency is often lower than price, so watch time alignment during aggregation.
- Update time: market data is strongly time-sensitive, and the timestamp determines whether a record is still “valid.” Data without a timestamp or with an unclear time zone should be treated as unusable.
2. Collection Layer Design: A Platform-Agnostic Pattern
Whether data comes from public APIs, an internal bus, or a third-party data service, the collection layer should follow the same set of principles.
2.1 Pull vs. Push Trade-offs
- Polling pull: simple to implement and controllable in state, suitable for low-to-medium frequency scenarios. The key is to set a reasonable polling interval and add jitter to avoid multiple instances saturating the upstream at the same time.
- Long-lived connection push: low latency and low resource usage, suitable for high-frequency market data. The cost is complex connection management, requiring heartbeats, reconnection, and disconnection compensation.
- Hybrid mode: using low-frequency pulls for static metadata (instrument lists, pair configuration) and push for dynamic prices is the most common combination in practice.
2.2 Timestamp and Window Alignment
Market data has three layers of time semantics: data generation time, data publication time, and data ingestion time. The three must be stored separately. When computing 24-hour statistics, window slicing must be based on data generation time; otherwise you introduce systematic bias.
from dataclasses import dataclassfrom datetime import datetime, timezone@dataclassclass Ticker:symbol: str # base instrumentquote: str # quote assetlast: float # last priceopen: float # open pricehigh: floatlow: floatchange: float # absolute changechange_pct: float # percentage changemarket_cap: float | Nonerank: int | Noneevent_time: datetime # data generation time (timezone-aware)def normalize(raw: dict) -> Ticker:symbol, quote = raw["pair"].split("/")t = Ticker(symbol=symbol, quote=quote,last=float(raw["last"]), open=float(raw["open"]),high=float(raw["high"]), low=float(raw["low"]),change=float(raw["change"]), change_pct=float(raw["change_pct"]),market_cap=raw.get("market_cap"), rank=raw.get("rank"),event_time=datetime.fromisoformat(raw["ts"]).replace(tzinfo=timezone.utc),)validate(t)return t
3. Validation Layer: Turning “Verifiable” into “Blockable”
Validation should run in layers: the earlier the layer, the cheaper it is; the later the layer, the stricter it is.
- Structural validation: whether required fields exist, whether types are convertible, whether enum values are legal (for example, whether the market type is in the whitelist).
- Range validation: prices must be positive; the high must not be below the low; the last must fall within
[low, high]. - Consistency validation: recompute the absolute and percentage change and compare against reported values, allowing a small threshold determined by precision.
- Time-series validation: the event time must not be significantly ahead of the current time (guarding against future timestamps) and must not be too old (guarding against stale data masquerading as real-time).
- Business validation: whether market cap and rank show magnitude jumps, and whether the change percentage exceeds a preset anomaly threshold.
def validate(t: Ticker, eps: float = 1e-4) -> None:assert t.last > 0 and t.open > 0, "prices must be positive"assert t.low <= min(t.open, t.last) <= max(t.open, t.last) <= t.high, "open/high/low/last containment is broken"assert abs((t.last - t.open) - t.change) < eps, "absolute change is inconsistent"calc_pct = (t.last - t.open) / t.openassert abs(calc_pct - t.change_pct) < 0.01, "percentage change is inconsistent"
It is worth stressing that validation failures should not be silently dropped; they should be written to a separate “quarantine area” with the failure reason attached, for later traceback and rule iteration. Silent dropping is the hardest source of problems to troubleshoot in a data pipeline.
4. Storage and Computation: Cold-Hot Tiering and Idempotent Writes
- Raw layer: keep the full unprocessed records, partitioned by time, for traceback and replay.
- Detail layer: standardized market data after structuring, with unified fields and dimensions, for querying and aggregation.
- Summary layer: pre-aggregated open/high/low/last and volume by minute/hour/day, for dashboards and reports.
Writes must be idempotent. Using (symbol, quote, event_time) as the unique key for deduplication avoids double counting caused by resends after reconnection. For out-of-order data, adopt a “watermark + allowed lateness” strategy: data beyond the lateness tolerance window enters a correction flow rather than directly overwriting the latest value.
Illustrative idempotent write logic:
INSERT INTO ticker_detail (symbol, quote, event_time, last, open, high, low, change, change_pct)VALUES (:symbol, :quote, :event_time, :last, :open, :high, :low, :change, :change_pct)ON CONFLICT (symbol, quote, event_time) DO UPDATESET last = EXCLUDED.last, high = GREATEST(ticker_detail.high, EXCLUDED.high),low = LEAST(ticker_detail.low, EXCLUDED.low);
5. Observability and Alerting
Failures in a market data pipeline are often “quiet”: no errors are raised, the data just gets slower or staler. So monitoring should be built around two dimensions: freshness and completeness.
- Freshness: the P95 and P99 of
current time - event timefor the latest record; alert when a threshold is exceeded. - Completeness: the ratio of the number of instruments that should arrive within a unit time window to the number that actually arrive.
- Consistency: validation failure rate and quarantine area backlog.
- Business anomalies: the number of records whose absolute change percentage exceeds a threshold or whose market cap shows a magnitude jump.
Suggested alert tiers: a slight freshness breach is a notice, a persistently growing quarantine backlog is a warning, and a core instrument stream outage is urgent. All alerts should carry locatable context (instrument, time, failure reason) to avoid “reporting only the symptom without a clue.”
6. Common Pitfalls and Engineering Advice
- Using floats directly for amount and price comparisons. Prices and absolute changes should use fixed-point or high-precision decimals, with an explicit precision threshold when comparing.
- Mixing timestamps from different time zones. Store uniformly in timezone-aware UTC and localize only at the presentation layer.
- Treating derived fields as authoritative data. Change percentage, market cap, and rank can all be recomputed, so use the raw price and circulating supply as the baseline.
- Ignoring “stale but well-formed” data. Passing format validation does not mean the data is valid; time-validity checks cannot be skipped.
- Lacking replay capability. Without retaining the raw layer, no logic change can have its effect verified.
7. Summary
A seemingly simple ticker record expands into a complete engineering effort across five stages: collection, validation, storage, computation, and monitoring. The core methodology comes down to three sentences: field semantics must be clear, derived relationships must be verifiable, and data timeliness must be measurable. Hard-code these three points into code and alert rules, and a market data pipeline can stay trustworthy over long-term operation. For further elastic scaling, you can combine a container platform to horizontally scale the stateless collection layer, use a message queue to smooth peaks and fill troughs, use object storage to archive the raw layer, and use logging and monitoring/alerting systems to close the loop on problem localization—these are all general-purpose technology categories, and specific choices should be evaluated against your own scale and compliance requirements.
