Building a Crypto Market Data Pipeline: Collection, Parsing, and Data Modeling Practices

    This article walks through the engineering practices behind a crypto market data pipeline, using a single public market snapshot as a worked example. It covers field classification and data modeling, UTC timestamp normalization, recomputing derived metrics such as price change and percentage change, data quality validation rules, collection strategies including polling intervals and backoff retries, hot/warm/cold storage tiering, observability and alerting, and common pitfalls to avoid. Readers will learn how to turn raw exchange fields into reliable, queryable, and auditable time-series data.

    1. Introduction: Why a Market Data Pipeline Matters More Than “Watching Prices”

    In crypto markets, prices move constantly and data updates arrive in dense bursts. Looking at a single quote at one moment has little engineering value. The real value comes from treating market data as a time-series stream: continuously collecting, standardizing, persisting, monitoring, and then exposing query and alerting capabilities. This article uses one public market snapshot as a sample and demonstrates the full path from raw fields to usable metrics.

    The sample record (described in neutral terms) is:

    • Symbol: GLM
    • Trading pair: GLMUSDT
    • Market type: CRYPTO
    • Latest price: 0.09359 USD
    • 24-hour change: 0.00009989
    • 24-hour change percentage: 0.107%
    • Open price: 0.09349
    • High price: 0.09539
    • Low price: 0.09119
    • Market cap: ~93.7331 million USD
    • Market cap rank: 164
    • Updated at: 2026-12-01 19:51:20

    This record looks simple, but it contains nearly every typical field type found in a market data system: identifiers, enums, prices, derived metrics, aggregate statistics, rank, and timestamps. Let’s break it down layer by layer.

    2. Field Semantics and Data Modeling

    2.1 Field Classification

    Group fields into four categories to make type constraints and validation easier:

    1. Identifiers: symbol, trading pair, market type. These are the source of primary keys and partition keys.
    2. Prices: latest price, open, high, low. All floating-point or fixed-point numbers.
    3. Derived: change amount, change percentage. Computed from the price series and should not be treated as the single source of truth.
    4. Statistics: market cap, market cap rank. Aggregate results whose definitions depend on the upstream calculation method.

    2.2 Modeling Recommendation

    The core design principle for a market data table is separating raw from derived. The raw snapshot table stores only the facts provided upstream; derived metrics are generated at the query or compute layer, so upstream definition changes do not pollute historical data.

    1. CREATE TABLE market_snapshot (
    2. symbol VARCHAR(16) NOT NULL, -- Symbol
    3. pair VARCHAR(24) NOT NULL, -- Trading pair
    4. market_type VARCHAR(16) NOT NULL, -- Market type enum
    5. price DECIMAL(18,8) NOT NULL, -- Latest price
    6. open_price DECIMAL(18,8),
    7. high_price DECIMAL(18,8),
    8. low_price DECIMAL(18,8),
    9. market_cap DECIMAL(20,2),
    10. cap_rank INT,
    11. ts_utc TIMESTAMP NOT NULL, -- Unified UTC time
    12. PRIMARY KEY (symbol, ts_utc)
    13. ) PARTITION BY RANGE (ts_utc);

    Key point: prices must use fixed-point numbers. Binary floating point produces tail differences during repeated accumulation and comparison, causing jitter on the order of 1e-8 in change-percentage calculations, which can trigger false alarms.

    3. Time Semantics and Timezone Governance

    The sample update time is 2026-12-01 19:51:20. Engineering must make three things explicit:

    • Whether the time is local time or UTC;
    • Whether it is the collection time, the upstream generation time, or the persistence time;
    • Whether second-level precision is enough for your polling interval.

    Practice: normalize everything to UTC on ingestion while keeping the original string field, forming a “dual timestamp.” This supports cross-source alignment and lets you trace back to the original evidence when disputes arise.

    1. from datetime import datetime, timezone
    2. def normalize(raw: str) -> datetime:
    3. # If upstream does not label the timezone, treat it as UTC and state this explicitly in the docs
    4. dt = datetime.strptime(raw, "%Y-%m-%d %H:%M:%S")
    5. return dt.replace(tzinfo=timezone.utc)

    4. Computing Derived Metrics Correctly

    Do not trust the upstream change percentage blindly; it should be recomputable. Definitions:

    • Change amount = latest price − price 24 hours ago
    • Change percentage = change amount / price 24 hours ago × 100%

    Reverse-engineering with the sample: 0.09359 − 0.00009989 ≈ 0.09349011, very close to the given open price of 0.09349. This suggests the snapshot’s “24-hour baseline price” approximately uses the starting price of a rolling window. The takeaway: different data sources may define “24 hours” as a rolling window or as a calendar day, and mixing them produces two sets of change percentages for the same symbol.

    1. from decimal import Decimal
    2. def change(price: Decimal, base: Decimal) -> tuple[Decimal, Decimal]:
    3. delta = price - base
    4. pct = (delta / base * Decimal("100")).quantize(Decimal("0.001"))
    5. return delta, pct

    5. Data Quality Validation Rules

    Pipeline stability depends on how complete the validation rules are. Implement at least these assertions:

    1. Range consistency: low ≤ open/latest ≤ high. In the sample, 0.09119 ≤ 0.09349 ≤ 0.09539, which passes.
    2. Non-negative and precision: all prices > 0, with no more than 8 decimal places.
    3. Enum whitelist: market type allows only a known set (e.g., CRYPTO); unknown values go to a quarantine area rather than being dropped.
    4. Monotonicity: timestamps for the same symbol must strictly increase; duplicate points are overwritten using an idempotency key.
    5. Jump detection: when the change percentage between adjacent snapshots exceeds a threshold (e.g., ±20%), mark it for review rather than storing it as fact.
    6. Market cap consistency: if there is an order-of-magnitude discrepancy among market cap, price, and circulating supply, record an alert.

    Data that fails validation should not be silently dropped. Write it to a “quarantine table + alert” to preserve traceability.

    6. Collection Strategy: Polling, Incremental Pull, and Caching

    • Polling interval: mainstream symbols every 5–15 seconds; long-tail symbols (e.g., ranked beyond the top 100 by market cap) can relax to 30–60 seconds to reduce cost.
    • Incremental pull: use (symbol, ts_utc) as the idempotency key and ignore duplicates during batch writes.
    • Local cache: keep the most recent snapshot in memory for fast derived-metric computation and frontend display, reducing repeated upstream requests.
    • Backoff retry: use exponential backoff on failure to avoid avalanche-style retries caused by transient jitter.
    1. import time, random
    2. def backoff(attempt: int, cap: int = 60) -> float:
    3. return min(cap, (2 ** attempt) + random.uniform(0, 1))

    7. Storage and Query Tiering

    A three-tier structure is recommended:

    1. Hot tier: the last 7 days, columnar storage or in-memory tables, serving real-time dashboards and alerts.
    2. Warm tier: the last 90 days, partitioned tables, serving backtests and metric computation.
    3. Cold tier: historical archives in object storage, loaded on demand.

    On the cloud, combine general-purpose capabilities: a message queue to carry collection events, a container platform to run collection and validation jobs, object storage for cold archiving, and logging plus monitoring/alerting services for observability. Use general category selections throughout to avoid tight coupling to a single implementation.

    8. Observability and Alerting

    Metrics that must be monitored include: collection success rate, end-to-end latency, validation failure rate, quarantine backlog, and per-symbol stream interruption duration. Alerts should be tiered: stream interruption and range conflicts are high severity, jumps pending review are medium, and precision alerts are low. Every alert should carry the symbol and the original timestamp for fast triage.

    9. Common Pitfalls

    • Storing change percentage as a fact, making history incomparable after upstream definition changes;
    • Using floating point for prices, producing tail differences over long accumulation;
    • Ignoring timezones, causing multi-hour offsets during cross-source alignment;
    • Dropping unknown enums outright, causing symbols to silently disappear;
    • Polling without backoff, amplifying failures when upstream jitters.

    10. Conclusion

    A seemingly ordinary market snapshot unfolds into a complete data engineering problem: modeling, timezones, precision, validation, collection, tiered storage, and observability. Make each stage an assertable, traceable, and reusable component, and market data becomes truly production-ready.