119 lines
3.1 KiB
Python
119 lines
3.1 KiB
Python
"""
|
|
Interface for data processing and normalization.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Dict, Union, List, Optional
|
|
from ..models.core import OrderBookSnapshot, TradeEvent, OrderBookMetrics
|
|
|
|
|
|
class DataProcessor(ABC):
|
|
"""Processes and normalizes raw exchange data"""
|
|
|
|
@abstractmethod
|
|
def normalize_orderbook(self, raw_data: Dict, exchange: str) -> OrderBookSnapshot:
|
|
"""
|
|
Normalize raw order book data to standard format.
|
|
|
|
Args:
|
|
raw_data: Raw order book data from exchange
|
|
exchange: Exchange name
|
|
|
|
Returns:
|
|
OrderBookSnapshot: Normalized order book data
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def normalize_trade(self, raw_data: Dict, exchange: str) -> TradeEvent:
|
|
"""
|
|
Normalize raw trade data to standard format.
|
|
|
|
Args:
|
|
raw_data: Raw trade data from exchange
|
|
exchange: Exchange name
|
|
|
|
Returns:
|
|
TradeEvent: Normalized trade data
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def validate_data(self, data: Union[OrderBookSnapshot, TradeEvent]) -> bool:
|
|
"""
|
|
Validate normalized data for quality and consistency.
|
|
|
|
Args:
|
|
data: Normalized data to validate
|
|
|
|
Returns:
|
|
bool: True if data is valid, False otherwise
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def calculate_metrics(self, orderbook: OrderBookSnapshot) -> OrderBookMetrics:
|
|
"""
|
|
Calculate metrics from order book data.
|
|
|
|
Args:
|
|
orderbook: Order book snapshot
|
|
|
|
Returns:
|
|
OrderBookMetrics: Calculated metrics
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def detect_anomalies(self, data: Union[OrderBookSnapshot, TradeEvent]) -> List[str]:
|
|
"""
|
|
Detect anomalies in the data.
|
|
|
|
Args:
|
|
data: Data to analyze for anomalies
|
|
|
|
Returns:
|
|
List[str]: List of detected anomaly descriptions
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def filter_data(self, data: Union[OrderBookSnapshot, TradeEvent],
|
|
criteria: Dict) -> bool:
|
|
"""
|
|
Filter data based on criteria.
|
|
|
|
Args:
|
|
data: Data to filter
|
|
criteria: Filtering criteria
|
|
|
|
Returns:
|
|
bool: True if data passes filter, False otherwise
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def enrich_data(self, data: Union[OrderBookSnapshot, TradeEvent]) -> Dict:
|
|
"""
|
|
Enrich data with additional metadata.
|
|
|
|
Args:
|
|
data: Data to enrich
|
|
|
|
Returns:
|
|
Dict: Enriched data with metadata
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_data_quality_score(self, data: Union[OrderBookSnapshot, TradeEvent]) -> float:
|
|
"""
|
|
Calculate data quality score.
|
|
|
|
Args:
|
|
data: Data to score
|
|
|
|
Returns:
|
|
float: Quality score between 0.0 and 1.0
|
|
"""
|
|
pass |