File size: 3,513 Bytes
e4e4574 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
"""Data models for the HuggingFace Crypto Data Engine"""
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel, Field
from datetime import datetime
class OHLCV(BaseModel):
"""OHLCV candlestick data model"""
timestamp: int = Field(..., description="Unix timestamp in milliseconds")
open: float = Field(..., description="Opening price")
high: float = Field(..., description="Highest price")
low: float = Field(..., description="Lowest price")
close: float = Field(..., description="Closing price")
volume: float = Field(..., description="Trading volume")
class OHLCVResponse(BaseModel):
"""Response model for OHLCV endpoint"""
success: bool = True
data: List[OHLCV]
symbol: str
interval: str
count: int
source: str
timestamp: Optional[int] = None
class Price(BaseModel):
"""Price data model"""
symbol: str
name: str
price: float
priceUsd: float
change1h: Optional[float] = None
change24h: Optional[float] = None
change7d: Optional[float] = None
volume24h: Optional[float] = None
marketCap: Optional[float] = None
rank: Optional[int] = None
lastUpdate: str
class PricesResponse(BaseModel):
"""Response model for prices endpoint"""
success: bool = True
data: List[Price]
timestamp: int
source: str
class FearGreedIndex(BaseModel):
"""Fear & Greed Index model"""
value: int = Field(..., ge=0, le=100)
classification: str
timestamp: str
class NewsSentiment(BaseModel):
"""News sentiment aggregation"""
bullish: int = 0
bearish: int = 0
neutral: int = 0
total: int = 0
class OverallSentiment(BaseModel):
"""Overall sentiment score"""
sentiment: str # "bullish", "bearish", "neutral"
score: int = Field(..., ge=0, le=100)
confidence: float = Field(..., ge=0, le=1)
class SentimentData(BaseModel):
"""Sentiment data model"""
fearGreed: FearGreedIndex
news: NewsSentiment
overall: OverallSentiment
class SentimentResponse(BaseModel):
"""Response model for sentiment endpoint"""
success: bool = True
data: SentimentData
timestamp: int
class MarketOverview(BaseModel):
"""Market overview data model"""
totalMarketCap: float
totalVolume24h: float
btcDominance: float
ethDominance: float
activeCoins: int
topGainers: List[Price] = []
topLosers: List[Price] = []
trending: List[Price] = []
class MarketOverviewResponse(BaseModel):
"""Response model for market overview endpoint"""
success: bool = True
data: MarketOverview
timestamp: int
class ProviderHealth(BaseModel):
"""Provider health status"""
name: str
status: str # "online", "offline", "degraded"
latency: Optional[int] = None # milliseconds
lastCheck: str
errorMessage: Optional[str] = None
class CacheInfo(BaseModel):
"""Cache statistics"""
size: int
hitRate: float
class HealthResponse(BaseModel):
"""Response model for health endpoint"""
status: str # "healthy", "degraded", "unhealthy"
uptime: int # seconds
version: str
providers: List[ProviderHealth]
cache: CacheInfo
class ErrorResponse(BaseModel):
"""Error response model"""
success: bool = False
error: ErrorDetail
timestamp: int
class ErrorDetail(BaseModel):
"""Error detail"""
code: str
message: str
details: Optional[dict] = None
retryAfter: Optional[int] = None
|