Collecting and Parsing Digital Asset Market Data: A Practical Guide

    This article walks through the engineering practices behind collecting and parsing digital asset market data, starting from a single ticker snapshot. It covers multi-layer symbol modeling, fixed-point price storage, internal consistency validation, time semantics, a layered ingestion pipeline, and observability with alerting. Readers will learn how to design a reliable market data service using generic messaging, object storage, and monitoring capabilities without relying on vendor-specific interfaces.

    1. Starting From a Single Ticker Snapshot

    In digital asset application development, market data is the most fundamental input and also the most error-prone. Below is a typical ticker snapshot (fields organized into a structured form):

    1. {
    2. "symbol": "GLM",
    3. "pair": "GLMUSDT",
    4. "market_type": "CRYPTO",
    5. "base_asset": "Golem",
    6. "last_price": 0.09359,
    7. "quote_currency": "USD",
    8. "change_24h": 0.00009989,
    9. "change_rate_24h": 0.107,
    10. "open_24h": 0.09349,
    11. "high_24h": 0.09539,
    12. "low_24h": 0.09119,
    13. "market_cap": 93733100,
    14. "rank": 164,
    15. "updated_at": "2026-12-01 19:58:31"
    16. }

    This record does not carry much information, yet it already covers the core dimensions of a market data system: instrument identity, last traded price, a 24-hour statistics window, market cap and rank, and the data timestamp. The real engineering questions are: what are the semantic boundaries of each field, which fields have verifiable constraints between them, and how should the system degrade when data is missing or delayed.

    2. Field Modeling: Clarify Semantics Before Storage

    2.1 The Multi-Layer Structure of Instrument Identity

    The raw data contains a symbol, a trading pair, a market type, and a name at the same time. This is not redundancy but four distinct layers:

    • Symbol (e.g., GLM): a short human-facing identifier, suitable for display and search;
    • Trading pair (e.g., GLMUSDT): the unique market key that determines the pricing basis;
    • Market type (CRYPTO): distinguishes crypto assets from other asset classes and affects risk parameters;
    • Name (Golem): the project name, used for display only and should not participate in any calculation logic.

    The most common mistake in practice is using the name or symbol as the primary key. The correct approach is to build a unique key from “market type + trading pair”, storing the symbol and name as附属 attributes.

    1. CREATE TABLE ticker_snapshot (
    2. market_type VARCHAR(16) NOT NULL,
    3. pair VARCHAR(32) NOT NULL,
    4. last_price DECIMAL(18,8) NOT NULL,
    5. quote_ccy CHAR(3) NOT NULL,
    6. change_rate DECIMAL(12,4),
    7. market_cap DECIMAL(20,2),
    8. rank_no INT,
    9. updated_at TIMESTAMP NOT NULL,
    10. PRIMARY KEY (market_type, pair, updated_at)
    11. );

    2.2 Prices Must Use Fixed-Point Numbers

    A decimal like 0.09359 stored as a floating-point value introduces errors during accumulation and comparison. Amounts and prices should uniformly use fixed-point decimals (DECIMAL) or integers in the smallest unit (such as a bigint scaled by 1e-8), with formatting done only at the presentation layer. This is the most easily overlooked and later the hardest to fix design flaw in a market data system.

    3. Consistency Validation: Let the Data Prove Itself

    A single ticker record contains multiple verifiable constraints. Writing them as pre-insertion validation rules can intercept the vast majority of dirty data:

    1. Range constraints: low ≤ open and last ≤ high. In the example above, 0.09119 ≤ 0.09349 and 0.09359 ≤ 0.09539 hold.
    2. Change consistency: last price − open price should approximately equal the 24-hour change. 0.09359 − 0.09349 = 0.00010, which matches the given 0.00009989 within precision.
    3. Change-rate consistency: change ÷ open × 100 ≈ 0.107%, consistent with 0.00009989 / 0.09349.
    4. Market cap sanity: market cap should equal price times circulating supply; a sudden change in magnitude often signals an anomaly in one of the data sources.
    5. Rank monotonicity: rank (164) changes should be continuous; a large jump should trigger manual review.
    1. def validate(t) -> list[str]:
    2. errs = []
    3. if not (t.low <= t.open <= t.high and t.low <= t.last <= t.high):
    4. errs.append("price_out_of_range")
    5. if abs((t.last - t.open) - t.change_24h) > 1e-6:
    6. errs.append("change_mismatch")
    7. if abs(t.change_24h / t.open * 100 - t.change_rate) > 0.01:
    8. errs.append("rate_mismatch")
    9. return errs

    Data that fails validation should not be discarded outright but written to a quarantine area with the failure reason attached, making it easier to trace data source quality.

    4. Time Semantics: The Hidden Difficulty of Market Data Systems

    updated_at is the most critical and most frequently misused field in the entire record. Three things must be made explicit:

    • The timezone must be declared explicitly. Strings lacking a timezone should be parsed under an agreed timezone and converted to a standard timezone-aware time on insertion.
    • Distinguish “data time” from “ingestion time”. The former describes when the market event occurred; the latter is used to troubleshoot pipeline latency. Both should be retained.
    • Use data time for deduplication and out-of-order handling. Upstream resends or network jitter can cause old data to arrive late, so select the maximum value within a window by data time rather than first-come-first-served.
    1. from datetime import datetime, timezone
    2. def parse_ts(s: str) -> datetime:
    3. return datetime.strptime(s, "%Y-%m-%d %H:%M:%S").replace(tzinfo=timezone.utc)

    5. Pipeline Architecture: Collection, Buffering, Computation, Serving

    A practical layered structure is as follows:

    1. Collection layer: poll the market data API on a schedule, dispatched independently per trading pair to avoid a single instrument blocking the whole.
    2. Buffering layer: use a message queue for peak shaving and decoupling, with the trading pair as the partition key to guarantee ordering for the same instrument.
    3. Computation layer: after consumption, run validation, unit normalization, and rolling window aggregation (such as 24-hour high/low and change rate).
    4. Storage layer: hot data goes to in-memory or time-series storage, historical data is archived to object storage, and hot/cold tiering controls cost.
    5. Serving layer: expose queries and push externally; responses must carry the data time so callers can judge freshness themselves.

    On Baidu AI Cloud, these layers can map respectively to compute and container platforms hosting collection and computation tasks, a message queue handling buffering, object storage handling archiving, and log service with monitoring and alerting handling observability. These are all general-purpose capability combinations that require no dependency on any specific proprietary interface.

    6. Observability and Alerting

    Failures in a market data pipeline often manifest as “the data is still there, but the data is wrong”. Monitoring therefore cannot look only at API success rate and should cover at least:

    • Freshness: the number of seconds since the latest data time; alert when it exceeds a threshold;
    • Validation failure rate: aggregated by reason; a spike indicates an upstream change;
    • Volatility anomalies: record an event when the absolute change rate exceeds a set threshold, rather than blocking directly;
    • Coverage: the ratio of expected instruments to actually received ones, to detect missed collection.
    1. alerts:
    2. - name: stale_data
    3. expr: now() - max(updated_at) > 60
    4. - name: validate_fail_spike
    5. expr: rate(validate_fail_total[5m]) > 5

    7. Summary

    A seemingly simple ticker snapshot expands into six engineering topics: instrument modeling, fixed-point precision, internal consistency validation, time semantics, a layered pipeline, and observability. Putting validation rules upfront, making time semantics explicit, and tiering hot and cold data is the minimum viable practice for building a reliable market data service. With general-purpose messaging, object storage, and monitoring and alerting capabilities, this pipeline can run stably without binding to any specific vendor’s proprietary interfaces.