Crypto Market Data Architecture: Field Parsing, Collection, Storage, and Monitoring
This article explains how to process crypto asset market data reliably for quantitative trading, market analysis, and risk control. It covers the technical meaning of core market data fields, a low-latency collection architecture based on WebSocket and message queues, data cleaning and time-series storage, and real-time monitoring and alerting. Developers and enterprise teams can use these practices to build resilient market data infrastructure for high-frequency data streams.
As blockchain technology becomes more widespread and the crypto asset market grows rapidly, the real-time performance, accuracy, and completeness of market data have become core foundations for quantitative trading, market analysis, and risk control. For developers and enterprise users, displaying a set of market numbers in a UI is far from enough. How to build a market data processing system from the underlying architecture that can handle high-frequency data streams and provide disaster recovery capabilities is a major challenge for technical teams. This article uses a typical set of crypto asset market data as an example and outlines related technical practices, from field parsing and collection architecture to data cleaning, storage, monitoring, and alerting.
1. Technical Interpretation of Core Market Data Fields
When processing crypto asset market data, we first need to understand the technical meaning of each core data field and how it is represented in the system. The following is a typical market data example with its technical interpretation:
- Token identifier and market type: This usually includes the token code (such as the abbreviation of a crypto asset), the trading pair (such as the exchange rate pair of a token against a stablecoin), and the market type (such as CRYPTO). In database design, these fields are often used as composite primary keys or index fields to uniquely locate a market data stream.
- Price fields: These include the latest price, open price, high price, and low price. In the example data, the latest price is 0.1154, the open price is 0.1138, the high price reaches 0.1208, and the low price is 0.1128. In systems, prices are usually stored as high-precision floating-point numbers or fixed-point numbers. Considering the problem of floating-point precision loss, the industry generally recommends string-based fixed-point representation or multiplying by a precision factor and storing the result as an integer to ensure calculation accuracy.
- Change amount and change percentage: The 24-hour change amount is 0.001598, and the change percentage is 1.405%. These two fields are derived metrics. They are usually calculated on the server side by the market data system and then delivered, or dynamically calculated by the client based on the latest price and the previous day’s closing price. In a stream processing architecture, such metrics are often aggregated in real time through sliding window functions.
- Market cap and ranking: The market cap is approximately 75.6663 million, and the ranking is 179. Market cap is usually calculated by multiplying the current circulating supply by the latest price. Such data has a relatively low update frequency, but it involves sorting calculations across all assets, so batch processing engines are often needed to refresh and cache it periodically in the background.
2. Market Data Collection Architecture Design
Crypto asset market data is high-frequency, highly concurrent, and runs 24/7. Therefore, the collection architecture must provide low latency and high availability.
1. Data access protocol selection
Exchanges or data sources usually provide both RESTful API and WebSocket interfaces. For tick-level data with extremely high real-time requirements, such as the latest price, high price, and low price, it is recommended to use WebSocket to establish a full-duplex long connection to reduce network overhead and latency caused by HTTP polling. For low-frequency data such as market cap rankings, scheduled tasks can call RESTful APIs.
2. Long connection management and disaster recovery
When using WebSocket to subscribe to data, robust heartbeat detection and reconnection mechanisms must be implemented. The following is a general pseudo-code example for long connection maintenance:
import asyncioimport websocketsimport jsonclass MarketDataSubscriber:def __init__(self, uri):self.uri = uriself.reconnect_interval = 5 # Reconnection interval in secondsasync def connect(self):while True:try:async with websockets.connect(self.uri) as websocket:await self.subscribe(websocket)await self.listen(websocket)except Exception as e:print(f"Connection lost: {e}. Reconnecting in {self.reconnect_interval}s...")await asyncio.sleep(self.reconnect_interval)async def subscribe(self, ws):sub_msg = {"action": "subscribe", "pairs": ["TARGET_USD"]}await ws.send(json.dumps(sub_msg))async def listen(self, ws):async for message in ws:data = json.loads(message)# Push data to a message queue or perform preprocessingawait self.process_data(data)async def process_data(self, data):# Data cleaning and validation logicpass
3. Peak shaving and message queues
When the market fluctuates sharply, the data push frequency may grow exponentially. Writing data directly to the database can cause the system to crash. Introducing a high-throughput message queue (such as a general-purpose distributed messaging middleware) as a buffer layer is a standard industry practice. Collector nodes push raw market data to the message queue, and downstream consumer nodes consume it smoothly according to their own processing capacity.
3. Data Cleaning and Storage Practices
Raw market data may contain outliers, duplicate frames, or out-of-order data, so it must go through a strict cleaning process.
1. Outlier filtering
For example, when a data record with a latest price of 0.1154 is received, but then a record with a latest price of 1.154 suddenly arrives, and no similar fluctuation occurs in other markets, the system should have an anomaly detection mechanism. Dirty data can be filtered by setting absolute thresholds or dynamic thresholds based on historical volatility, such as a Bollinger Bands strategy.
2. Data deduplication and sorting
Due to reasons such as network retransmission, duplicate data packets may be received. The system should use timestamps or auto-increment sequence numbers in the data packets for deduplication. For out-of-order data, a time window mechanism based on a stream processing engine can be introduced to sort the data within the window before persistence.
3. Storage medium selection
Given the time-series characteristics of market data, relational databases have obvious performance bottlenecks when storing and querying massive amounts of time-series data. Dedicated time-series databases (TSDBs) are recommended. These databases are deeply optimized for write throughput, data compression ratio, and time-range-based aggregation queries. For example, storing indicators such as high price, low price, and open price at minute-level or hour-level downsampling can save storage space and accelerate long-term trend queries.
4. Real-Time Monitoring and Alerting Mechanism
The ultimate value of market data lies in guiding business decisions and risk prevention. A complete monitoring and alerting system is indispensable.
1. Metric calculation and stream processing
Using a stream computing framework, market data in the message queue can be consumed in real time to calculate derived metrics such as the 24-hour change percentage (1.405%), moving averages, and the Relative Strength Index. These metrics are not only used for frontend display but also serve as the basis for triggering risk control rules.
2. Rule engine and alerting
Connect the calculated metrics to a rule engine. For example, when the market cap of an asset falls below a specific threshold, or when the decline within a short period exceeds a preset percentage, the rule engine immediately triggers an alert event.
3. General cloud service integration
In a cloud-native architecture, alert events can be seamlessly integrated with general-purpose log services and monitoring and alerting platforms. For example, with a cloud monitoring service, developers can easily configure multi-dimensional alert policies and push alert information to operations or trading teams through channels such as SMS, email, or Webhook. At the same time, using cloud log services to uniformly search historical market data and system runtime logs helps quickly locate root causes during post-incident reviews.
5. Conclusion
Processing crypto asset market data is not simply moving numbers around. It is a comprehensive systems engineering task involving network programming, high-concurrency architecture, data cleaning, time-series storage, and real-time computing. Developers need to deeply understand the technical meaning of each market data field, build collection modules with disaster recovery capabilities, and use message queues and time-series databases to achieve smooth data flow and efficient storage. With mature monitoring and alerting mechanisms and cloud-native services, enterprises can build stable and efficient market data infrastructure and gain technical and data advantages in the rapidly changing crypto asset market.
