Crypto Market Data Ingestion and Parsing: A Generic Ticker API Example

    This article uses a generic cryptocurrency ticker record to explain how market data is structured and parsed. It covers field semantics, 24-hour change and market-cap calculations, timestamp requirements, a strongly typed data model, and engineering practices for ingestion, validation, caching, and display, with generic Python examples for modeling and validation.

    In digital asset trading systems, market data is one of the most fundamental and important types of information. Whether the system is a market dashboard, a quantitative analysis tool, or a portfolio management application, it depends on understanding and processing fields such as latest price, percentage change, market cap, and rank. Using a typical cryptocurrency ticker record as the starting point—without any platform-specific information—this article explains ticker data structure design, field parsing, calculation logic, and engineering practices, and provides generic examples for modeling and processing.

    1. What Information a Ticker Record Contains

    A complete spot market ticker record usually contains the following categories of information:

    1. Identifier information: trading asset code, trading pair symbol, and market type. For example, a token’s code, its corresponding USDT-quoted trading pair, and the fact that it belongs to the cryptocurrency market.
    2. Price information: latest traded price, open price, 24-hour high, 24-hour low, and quote currency (such as USD).
    3. Volatility information: absolute price change and percentage change over the past 24 hours.
    4. Scale information: circulating market cap and market cap rank.
    5. Metadata: data update timestamp.

    Consider a sample record: the latest price is 0.07971, the open price is 0.07911, the 24-hour high is 0.08381, the 24-hour low is 0.07831, the absolute change is about 0.0006, the percentage change is about 0.758%, the market cap is about USD 27.8983 million, and the market cap rank is 455. Behind each of these numbers is a distinct business meaning and calculation rule, as described below.

    2. Semantics and Calculation Logic of Core Fields

    2.1 How Percentage Change Is Calculated

    Percentage change is one of the most frequently misinterpreted fields in ticker data. Its usual definition is:

    1. percentage change = (latest price - price 24 hours ago) / price 24 hours ago × 100%

    Note that the baseline here is the “price 24 hours ago,” not the “current day’s open price.” Using the sample data: with an absolute change of 0.0005993 and a percentage change of 0.758%, the implied baseline price is approximately 0.0005993 / 0.00758 ≈ 0.07906, slightly lower than the open price of 0.07911. This indicates that the data source indeed uses the snapshot price from 24 hours earlier as the baseline for percentage change. When implementing this themselves, developers must keep their calculation logic consistent with the data source; otherwise, the frontend display may appear inconsistent with other values.

    2.2 Meaning of Market Cap and Rank

    Market cap generally refers to circulating market cap, which is circulating supply multiplied by the current price:

    1. circulating market cap = circulating supply × latest price

    From the market cap of USD 27.8983 million and the price of 0.07971, the circulating supply can be inferred to be approximately 350 million tokens. Market cap rank reflects the asset’s relative position by size across the broader market (455 in the example). This metric is useful in asset screening and risk-tiering scenarios. Generally, the lower the rank, the worse the liquidity and the higher the volatility risk.

    2.3 Importance of Timestamps

    Ticker data is strongly time-sensitive. The update time (for example, 17:10:29 on a certain day) must be stored and transmitted together with the data. Ticker data without a timestamp can seriously mislead users at the presentation layer, especially in systems where caching and real-time push coexist.

    3. Generic Data Model Design

    A strongly typed structure is recommended for modeling ticker data. The following is an illustrative definition:

    1. from dataclasses import dataclass
    2. from datetime import datetime
    3. @dataclass
    4. class TickerSnapshot:
    5. symbol: str # Trading pair, e.g. XXXUSDT
    6. base_asset: str # Base asset code
    7. market_type: str # Market type, e.g. CRYPTO
    8. quote_currency: str # Quote currency, e.g. USD
    9. last_price: float # Latest price
    10. open_price: float # Open price
    11. high_24h: float # 24-hour high
    12. low_24h: float # 24-hour low
    13. change_abs: float # 24-hour absolute change
    14. change_pct: float # 24-hour percentage change
    15. market_cap: float # Circulating market cap
    16. market_cap_rank: int # Market cap rank
    17. updated_at: datetime # Update time
    18. @property
    19. def amplitude(self) -> float:
    20. """Amplitude: (high - low) / open price"""
    21. if self.open_price == 0:
    22. return 0.0
    23. return (self.high_24h - self.low_24h) / self.open_price * 100

    Encapsulating field semantics in the model and deriving additional indicators such as amplitude allows upper-layer business code to avoid dealing with calculation details and makes it easier to provide a unified adapter across multiple data sources.

    4. Engineering Considerations for the Data Ingestion Pipeline

    4.1 Combining Pulling and Pushing

    Ticker data is usually obtained in two ways: scheduled polling of REST interfaces or subscribing to WebSocket pushes. Polling is simple to implement and suitable for low-frequency scenarios; push has lower latency and is suitable for real-time dashboards. A common practice is “push as the primary mechanism, polling as fallback”: when the push connection is interrupted, the system degrades to polling to keep data flowing.

    4.2 Validation and Fault Tolerance

    When ingesting external ticker data, at least the following validations should be performed:

    • Numeric validity: prices and market cap must be non-negative, and the high price must not be lower than the low price;
    • Timestamp freshness: data that has not been updated beyond a certain threshold should be marked as “delayed” or “invalid”;
    • Abnormal volatility detection: an alert can be triggered when the percentage change in a single update exceeds a configured threshold, preventing dirty data from affecting the presentation layer.
    1. def validate(t: TickerSnapshot, max_staleness_sec=60) -> bool:
    2. now = datetime.utcnow()
    3. if t.last_price <= 0 or t.high_24h < t.low_24h:
    4. return False
    5. if (now - t.updated_at).total_seconds() > max_staleness_sec:
    6. return False
    7. return True

    4.3 Caching and Presentation

    Ticker data is read-heavy and write-light, and short delays are acceptable, making it well suited to an in-memory cache or message queue for peak shaving. For frontend display, it is recommended to show both the update time and the calculation convention of the data source (such as the baseline for percentage change) to improve the credibility and explainability of the information.

    5. Summary

    Ticker data may look like a string of numbers, but each field has a clear business definition and calculation convention. When building ticker-related systems, developers should focus on the baseline used for percentage change, the conversion relationship between market cap and circulating supply, the completeness of timestamps, and validation and fault-tolerance design in the ingestion pipeline. With clear domain modeling and a layered data-processing flow, it is possible to build an accurate and robust ticker data service that provides a solid foundation for analytics, trading, and presentation features.