Features: - FastAPI backend with stocks, news, signals, watchlist, analytics endpoints - React frontend with TailwindCSS dark mode trading dashboard - Celery workers for news fetching, sentiment analysis, pattern detection - TimescaleDB schema for time-series stock data - Docker Compose setup for all services - OpenAI integration for sentiment analysis
47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Buy signal model."""
|
|
|
|
from sqlalchemy import Column, String, DateTime, Numeric, Integer, ForeignKey
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.sql import func
|
|
import uuid
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class BuySignal(Base):
|
|
"""Buy signal table model."""
|
|
|
|
__tablename__ = "buy_signals"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
stock_id = Column(UUID(as_uuid=True), ForeignKey("stocks.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
panic_event_id = Column(UUID(as_uuid=True), ForeignKey("panic_events.id", ondelete="SET NULL"))
|
|
|
|
# Signal details
|
|
signal_time = Column(DateTime(timezone=True), nullable=False, server_default=func.now(), index=True)
|
|
signal_price = Column(Numeric(15, 4), nullable=False)
|
|
|
|
# Confidence scoring
|
|
confidence_score = Column(Numeric(5, 4), nullable=False, index=True) # 0 to 1
|
|
|
|
# Based on pattern
|
|
pattern_id = Column(UUID(as_uuid=True), ForeignKey("historical_patterns.id", ondelete="SET NULL"))
|
|
expected_recovery_percent = Column(Numeric(8, 4))
|
|
expected_recovery_days = Column(Integer)
|
|
|
|
# Current metrics
|
|
current_drawdown_percent = Column(Numeric(8, 4))
|
|
current_sentiment_score = Column(Numeric(5, 2))
|
|
|
|
# Signal status
|
|
status = Column(String(20), default="active", index=True) # active, triggered, expired, cancelled
|
|
triggered_at = Column(DateTime(timezone=True))
|
|
|
|
# Outcome tracking
|
|
outcome_price = Column(Numeric(15, 4))
|
|
outcome_percent = Column(Numeric(8, 4))
|
|
outcome_days = Column(Integer)
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|