- shared/schemas/trading.py: OrderRequest, OrderResult, PositionInfo, AccountInfo, TradeSignal, TradeExecution, MarketSnapshot, SentimentContext - shared/schemas/news.py: RawArticle, ScoredArticle - shared/schemas/learning.py: TradeOutcomeSchema, WeightAdjustment - shared/schemas/auth.py: RegisterRequest, LoginRequest, TokenResponse - 49 schema tests covering validation constraints, serialization round-trips, required fields, and range checks
44 lines
1 KiB
Python
44 lines
1 KiB
Python
"""News article Pydantic schemas for Redis Stream messages."""
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class RawArticle(BaseModel):
|
|
"""Published to ``news:raw`` by the news fetcher."""
|
|
|
|
source: str
|
|
url: str
|
|
title: str
|
|
content: str
|
|
published_at: datetime | None = None
|
|
fetched_at: datetime
|
|
content_hash: str
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class ScoredArticle(BaseModel):
|
|
"""Published to ``news:scored`` by the sentiment analyzer.
|
|
|
|
Inherits all fields from RawArticle conceptually plus scoring metadata.
|
|
"""
|
|
|
|
# Original article fields
|
|
source: str
|
|
url: str
|
|
title: str
|
|
content: str
|
|
published_at: datetime | None = None
|
|
fetched_at: datetime
|
|
content_hash: str
|
|
|
|
# Scoring fields
|
|
ticker: str
|
|
sentiment_score: float = Field(ge=-1.0, le=1.0)
|
|
confidence: float = Field(ge=0.0, le=1.0)
|
|
model_used: str
|
|
entities: list[str] = Field(default_factory=list)
|
|
|
|
model_config = {"from_attributes": True}
|