Designing a Cryptocurrency Market Data System: Parsing and Service Construction
This article explores the design and implementation of a cryptocurrency market data system. It covers the typical structure of market snapshots, data parsing and validation, multi-source aggregation, storage strategies, and external API design. By following these engineering practices, developers can build a reliable, scalable, and consistent market data service for digital assets.
Designing a Crypto Market Data System from a Single Snapshot
1. Typical Structure of Market Data
In the digital asset domain, a market snapshot typically contains a set of standardized fields. Taking a trading pair as an example, the core fields can be abstracted as follows:
- Identifier Information: Asset code, trading pair name, market type (e.g., CRYPTO)
- Price Information: Latest price, open price, highest price (high), lowest price (low)
- Statistical Information: 24-hour change, change percentage, market capitalization, and market cap ranking
- Metadata: Quote currency, data update timestamp
For instance, a real snapshot might look like: latest price 0.09139 USD, up 0.002697 (approx. 3.041%) from the previous day, open price 0.08869, 24h high 0.09368, 24h low 0.08759, market cap around 90.54 million USD, ranked 168th, updated at 2026-11-24 14:33:41. This set of data covers the minimal complete set required by a market data system.
Understanding field semantics is a prerequisite for subsequent processing. For example, “24h change” is typically defined as the difference between the current price and the price 24 hours ago (or the day’s open price, depending on exchange rules). Market capitalization is the product of circulating supply and the latest price. Definitions may vary across data sources, so unifying the calculation standards during aggregation is essential.
2. Data Parsing and Validation
Common ways to obtain market data include REST API polling and WebSocket push. After retrieving the data, the first step is parsing and validation:
def parse_ticker(raw: dict) -> dict:required = ["symbol", "last", "open", "high", "low"]for k in required:if k not in raw:raise ValueError(f"missing field: {k}")last, low, high = float(raw["last"]), float(raw["low"]), float(raw["high"])# Basic validity check: prices must be positive, high/low range must cover the latest priceif last <= 0 or not (low <= last <= high):raise ValueError("invalid price range")change = last - float(raw["open"])pct = change / float(raw["open"]) * 100return {"symbol": raw["symbol"],"last": last, "low": low, "high": high,"change": round(change, 6),"change_pct": round(pct, 3),}
Validation logic should include at least three categories: Completeness validation (whether required fields exist), Type validation (whether numeric fields can be converted), and Business validation (e.g., whether high/low prices cover the latest price, whether the change percentage is within a reasonable threshold; exceeding the threshold may indicate a flash crash or dirty data, requiring an alert rather than direct insertion into the database).
3. Aggregation and Calculation
In multi-source data scenarios, quotes for the same trading pair may differ across data sources. A common practice is to use the Volume-Weighted Average Price (VWAP) as the benchmark price while retaining details from each source for auditing. Special attention should be paid to the baseline selection when calculating price changes:
- Relative to open price: Suitable for displaying “intraday change”; the open price is fixed daily, ensuring stable data.
- Relative to price 24 hours ago: A rolling window with better real-time performance, but heavily reliant on historical snapshots, making it prone to errors when data is missing.
Engineering-wise, it is recommended to consolidate calculation logic into an independent module with unified output standards. This prevents inconsistencies between frontend and backend numbers caused by separate calculations in the presentation layer.
4. Storage and Real-Time Updates
Market data is characterized by frequent writes and reads with a small individual size. A typical storage architecture includes:
- Cache Layer: Uses in-memory key-value stores to save the latest snapshot. The key is the trading pair, and the value is the serialized market object, ensuring low read latency.
- Time-Series Database: Persists historical K-lines or snapshots at fixed frequencies. Supports time-range queries for drawing trend charts and backtesting.
- Message Queue: Price update events are pushed into the queue for downstream consumption, such as alerts, statistics, and push notifications, achieving producer-consumer decoupling.
Regarding update strategies, mainstream trading pairs can use second-level pushes, while long-tail assets can be relaxed to minute-level to save resources. Meanwhile, retaining an updated_at field in the snapshot allows the frontend to assess data freshness. If the data is not updated within the expected timeframe, it is marked as “data delayed” to prevent users from mistaking stale prices for real-time prices.
5. External API Design
The external query interface of a market data service should support three levels of granularity:
GET /tickers/{symbol} # Latest snapshot for a single trading pairGET /tickers?symbols=A,B,C # Batch queryGET /tickers/{symbol}/history?interval=1m&limit=240 # Historical K-lines
The response body should include price, range statistics, change percentage, timestamp, and market type. For abnormal trading pairs, it should return explicit error codes rather than null values. Batch queries can significantly reduce the number of requests in list page scenarios. Combined with server-side caching and rate limiting, it can smoothly support peak traffic.
6. Reliability Practices Summary
When building a market data service, the following aspects are worth significant investment:
- Unified Definitions: The calculation rules for price changes and market cap must be globally unique and documented in a data dictionary.
- Dirty Data Defense: Price jump threshold detection, strict field type validation, and out-of-order timestamp handling.
- Degradation Capability: Cache the last valid snapshot and mark it as delayed during upstream data source failures, rather than returning an error.
- Observability: Integrate logging services and monitoring alerts, setting threshold alerts for update latency and parsing failure rates.
Market data may seem simple, but it is actually a systems engineering trade-off among “data accuracy, real-time performance, and consistency.” From field modeling, parsing, and validation to aggregation, calculation, storage, and API design, each layer has clear engineering boundaries. Mastering this methodology allows you to build a trustworthy and scalable market data service for any digital asset or quote currency.
