212 lines
4.4 KiB
Python
212 lines
4.4 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
|
|
class TradeAction(str, Enum):
|
|
BUY = "BUY"
|
|
SELL = "SELL"
|
|
|
|
|
|
class Recommendation(str, Enum):
|
|
BUY = "BUY"
|
|
SELL = "SELL"
|
|
HOLD = "HOLD"
|
|
|
|
|
|
class RiskLevel(str, Enum):
|
|
LOW = "LOW"
|
|
MEDIUM = "MEDIUM"
|
|
HIGH = "HIGH"
|
|
|
|
|
|
class PriceData(BaseModel):
|
|
time: int
|
|
open: float
|
|
high: float
|
|
low: float
|
|
close: float
|
|
volume: Optional[float] = None
|
|
|
|
|
|
class TradeCreate(BaseModel):
|
|
action: TradeAction
|
|
quantity: float
|
|
price: float
|
|
|
|
|
|
class TradeResponse(BaseModel):
|
|
id: int
|
|
simulation_id: int
|
|
action: TradeAction
|
|
quantity: float
|
|
price: float
|
|
total: float
|
|
pnl: Optional[float] = None
|
|
timestamp: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PositionResponse(BaseModel):
|
|
symbol: str
|
|
quantity: float
|
|
avg_price: float
|
|
current_price: float
|
|
unrealized_pnl: float
|
|
unrealized_pnl_percent: float
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PortfolioResponse(BaseModel):
|
|
cash: float
|
|
initial_capital: float
|
|
total_value: float
|
|
total_pnl: float
|
|
total_pnl_percent: float
|
|
position: Optional[PositionResponse] = None
|
|
trades: List[TradeResponse] = []
|
|
|
|
|
|
class MarketDataResponse(BaseModel):
|
|
symbol: str = "XAU/USD"
|
|
price: float
|
|
change: float
|
|
change_percent: float
|
|
high_24h: float
|
|
low_24h: float
|
|
volume: float
|
|
|
|
|
|
class SupportResistance(BaseModel):
|
|
support: List[float] = []
|
|
resistance: List[float] = []
|
|
|
|
|
|
class AIAnalysisRequest(BaseModel):
|
|
price_data: List[PriceData]
|
|
indicators: List[dict]
|
|
current_price: float
|
|
|
|
|
|
class AIAnalysisResponse(BaseModel):
|
|
recommendation: Recommendation
|
|
confidence: float = Field(..., ge=0, le=100)
|
|
reasoning: str
|
|
support_resistance: SupportResistance
|
|
risk_level: RiskLevel
|
|
|
|
|
|
class IndicatorData(BaseModel):
|
|
time: int
|
|
value: float
|
|
|
|
|
|
# News and Sentiment Schemas
|
|
class Sentiment(str, Enum):
|
|
POSITIVE = "POSITIVE"
|
|
NEGATIVE = "NEGATIVE"
|
|
NEUTRAL = "NEUTRAL"
|
|
|
|
|
|
class NewsArticle(BaseModel):
|
|
id: str
|
|
source: str
|
|
title: str
|
|
description: Optional[str] = None
|
|
url: str
|
|
published_at: datetime
|
|
sentiment: Sentiment
|
|
sentiment_score: float = Field(..., ge=-1, le=1)
|
|
impact_on_gold: str # HIGH, MEDIUM, LOW
|
|
relevance_score: float = Field(..., ge=0, le=1)
|
|
category: str # MONETARY_POLICY, GEOPOLITICS, ECONOMIC_DATA, etc.
|
|
|
|
|
|
class NewsFeedResponse(BaseModel):
|
|
articles: List[NewsArticle]
|
|
total_count: int
|
|
bullish_count: int
|
|
bearish_count: int
|
|
neutral_count: int
|
|
overall_sentiment: Sentiment
|
|
avg_sentiment_score: float
|
|
|
|
|
|
class EconomicEvent(BaseModel):
|
|
id: str
|
|
title: str
|
|
country: str
|
|
currency: str
|
|
event_date: datetime
|
|
importance: str # HIGH, MEDIUM, LOW
|
|
forecast: Optional[str] = None
|
|
previous: Optional[str] = None
|
|
actual: Optional[str] = None
|
|
impact_on_gold: str
|
|
|
|
|
|
class EconomicCalendarResponse(BaseModel):
|
|
events: List[EconomicEvent]
|
|
upcoming_high_impact: int
|
|
|
|
|
|
# Alert Schemas
|
|
class AlertType(str, Enum):
|
|
PRICE_SPIKE = "PRICE_SPIKE"
|
|
PRICE_DROP = "PRICE_DROP"
|
|
NEWS_BREAKING = "NEWS_BREAKING"
|
|
SUPPORT_BREACH = "SUPPORT_BREACH"
|
|
RESISTANCE_BREACH = "RESISTANCE_BREACH"
|
|
HIGH_VOLATILITY = "HIGH_VOLATILITY"
|
|
ECONOMIC_EVENT = "ECONOMIC_EVENT"
|
|
|
|
|
|
class AlertSeverity(str, Enum):
|
|
CRITICAL = "CRITICAL"
|
|
HIGH = "HIGH"
|
|
MEDIUM = "MEDIUM"
|
|
LOW = "LOW"
|
|
|
|
|
|
class Alert(BaseModel):
|
|
id: str
|
|
type: AlertType
|
|
severity: AlertSeverity
|
|
title: str
|
|
message: str
|
|
price: Optional[float] = None
|
|
change_percent: Optional[float] = None
|
|
timestamp: datetime
|
|
related_news: Optional[List[str]] = [] # URLs to related news
|
|
action_required: bool = False
|
|
|
|
|
|
class AlertsResponse(BaseModel):
|
|
alerts: List[Alert]
|
|
critical_count: int
|
|
unread_count: int
|
|
|
|
|
|
# News-Price Correlation
|
|
class NewsPriceCorrelation(BaseModel):
|
|
news_id: str
|
|
news_title: str
|
|
news_time: datetime
|
|
price_before: float
|
|
price_after: float
|
|
price_change: float
|
|
price_change_percent: float
|
|
time_delta_minutes: int
|
|
correlation_strength: str # STRONG, MODERATE, WEAK
|
|
|
|
|
|
class CorrelationAnalysisResponse(BaseModel):
|
|
correlations: List[NewsPriceCorrelation]
|
|
significant_events: int
|
|
avg_price_impact: float
|