Digital Asset Market Data: Collection and Processing Best Practices
This article explains how to build a reliable digital asset market data pipeline, from defining a common quote model to combining polling with streaming updates. It covers price precision, timestamp handling, data validation, tiered storage, incremental processing, and how to serve stale data transparently when an upstream feed fails.
1. Why Market Data Is Hard to Get Right
A quote may look like a price and a handful of statistics, but turning upstream feeds into reliable data presents four engineering challenges:
- Freshness: Market data loses value quickly. The polling interval, network jitter, and the provider’s update cadence can combine to make a displayed price stale.
- Consistency: Quotes for the same asset are not interchangeable across trading pairs or market types. Mixing them can produce misleading statistics.
- Precision and units: Providers may return prices as strings or floating-point numbers and use different tick sizes, quote currencies, or market cap units. Using those values directly in calculations can compound errors.
- Completeness: Missing fields, timestamp drift, and prolonged feed interruptions are common. Without validation, bad data can make its way to the display layer.
The goal is not simply to fetch data from an API. It is to build a pipeline that validates quotes, makes them traceable, and degrades gracefully when a feed fails.
2. Define a Common Quote Model Before Writing Collectors
Whatever shape the upstream payload takes, normalize it to a stable internal contract.
| Category | Fields | Handling |
|---|---|---|
| Identity | Asset symbol, trading pair, market type | Keep all three explicit. The example below uses market type and trading pair as the lookup key. |
| Prices | Last, open, high, low | Use fixed-point decimals. |
| Statistics | 24-hour price change and percentage change | Validate the values reported by the provider. |
| Market size | Market capitalization and market cap rank | Check units and how the provider calculates each metric. |
| Time | Provider update timestamp | Normalize to UTC before storing. |
An illustrative Python model:
from dataclasses import dataclassfrom decimal import Decimalfrom datetime import datetime, timezone@dataclass(frozen=True)class Quote:symbol: str # Asset symbolpair: str # Trading pairmarket: str # Market typelast: Decimal # Last priceopen: Decimalhigh: Decimallow: Decimalchange: Decimal # 24-hour price changechange_pct: Decimal # 24-hour percentage change (%)market_cap: Decimal # Market capitalizationrank: int # Market cap rankts: datetime # Provider update timestamp (UTC)@propertydef key(self) -> tuple:return (self.market, self.pair)
Use fixed-point decimal arithmetic with Decimal rather than binary floating point for monetary values. This avoids representation errors that can accumulate when working with values such as 0.1. Store only timezone-aware timestamps.
3. Choose Between Polling and Streaming
Polling is simple and stateless. It works well when the number of assets is limited and the required update frequency is moderate.
- Set the polling interval no shorter than the provider’s update interval to avoid redundant requests.
- Retry with exponential backoff, cap the number of attempts, and set a circuit-breaker threshold.
- Respect upstream rate limits by using a client-side token bucket.
- Record request duration and status codes to track feed health.
Streaming over a persistent connection can lower latency and reduce resource use, but it requires keepalives, reconnection, subscription recovery, and message deduplication. A common approach is to use streaming for low-latency updates and infrequent polling to reconcile the full snapshot. Use provider timestamps to decide whether an incoming quote should replace the stored one.
def is_stale(new: Quote, old: Quote, max_lag_seconds: int = 30) -> bool:now = datetime.now(timezone.utc)if (now - new.ts).total_seconds() > max_lag_seconds:return Truereturn old is not None and new.ts <= old.ts # Reject duplicates and older updates.
4. Normalize Prices and Validate Derived Metrics
Normalize and validate raw records before they reach downstream consumers:
- Normalize units. If the provider reports market capitalization in scaled units, convert it to base units before storing it. Apply display formatting at the presentation layer.
- Enforce price precision. Set the minimum price increment for each instrument. Truncate values that exceed the supported precision rather than rounding them into a different price level.
- Check internal consistency. Verify that
low ≤ last ≤ highand that the reported 24-hour change is approximatelylast − open24h. Flag records when the discrepancy exceeds the configured tolerance. - Recalculate percentage change. Use
(last − open) / open × 100, whereopenis the opening price for the same reporting window. If the result differs materially from the provider’s value, use the recalculated value and raise an alert. - Review unusual rank changes. Check large jumps in market cap rank against movements in market capitalization. Rank is relative, so treat a mismatch as a signal for manual review rather than proof of bad data.
5. Separate Storage, Processing, and Presentation
Organize storage by access pattern:
- Hot data: Keep current quotes in an in-memory cache, such as a local dictionary with a short TTL, for online queries.
- Warm data: Store recent history in a time-series database partitioned by instrument and time to support aggregation over time ranges.
- Cold data: Archive records in object storage for historical investigation and offline analysis.
Process updates incrementally. When a quote arrives, update only the statistical windows for the affected instrument instead of recomputing everything. Broadcast changes to subscribers through a message queue. On the frontend, render an initial snapshot and apply incremental updates to avoid unnecessary refreshes.
6. Monitor Freshness and Plan for Failures
Track collection success rate, end-to-end latency, data staleness, missing-field rate, and validation failure rate. Match the alert severity to the scope of the problem: one stale instrument may warrant a warning, while a feed interruption across many instruments calls for a critical alert.
Define fallback behavior before an outage. If the upstream feed is unavailable, serve the last valid snapshot and show its timestamp. On a cache miss, fetch from the upstream source. If that fetch fails and no valid snapshot is available, return an explicit data temporarily unavailable state. Never fill a missing price with zero or a default value.
7. Deploy in the Cloud Without Exposing Trading Credentials
A container platform can host and scale collection and processing services, while a message queue decouples producers from consumers. Use the cache, time-series database, and object storage for the hot, warm, and cold tiers, respectively. Centralize logs for troubleshooting, and use monitoring and alerting to track both service health and data quality across the pipeline.
The pipeline handles public, read-only market data. It neither needs account private keys nor performs transaction signing. Store any required access credentials in a managed secrets service instead of hardcoding them in source code or container images. Protect public-facing endpoints with authentication and rate limiting to prevent abuse.
8. Takeaway
Reliability depends less on how fast you call an API than on whether you have a consistent data model, early validation, explicit fallback behavior, and enough visibility to detect failures. With those pieces in place, upstream payloads can change without breaking the internal contract, leaving you free to focus on data quality and latency.
