da0bb3367e
Store an optional company name on Ticker (migration 014) and backfill it from Alpaca's asset list in a single Trading-API call for the whole universe — no per-ticker fetch. Runs automatically at the end of universe bootstrap and via a manual "Backfill Names" button (admin) / POST /admin/tickers/backfill-names. The name ships on /tickers; a shared symbol→name map (useTickerNames) lets any view show it without its own request. Displayed subtly next to the symbol — in the global search, the ticker header, and as a small muted line under the symbol in Top Setups and Open Trades (no extra column, truncated so it never widens the table). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
31 lines
1.6 KiB
Python
31 lines
1.6 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import String, DateTime
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class Ticker(Base):
|
|
__tablename__ = "tickers"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
symbol: Mapped[str] = mapped_column(String(10), unique=True, nullable=False)
|
|
# Company name (e.g. "Biogen Inc."); backfilled from Alpaca, nullable for
|
|
# symbols Alpaca doesn't know.
|
|
name: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
# Relationships (cascade deletes)
|
|
ohlcv_records = relationship("OHLCVRecord", back_populates="ticker", cascade="all, delete-orphan")
|
|
sentiment_scores = relationship("SentimentScore", back_populates="ticker", cascade="all, delete-orphan")
|
|
fundamental_data = relationship("FundamentalData", back_populates="ticker", cascade="all, delete-orphan")
|
|
sr_levels = relationship("SRLevel", back_populates="ticker", cascade="all, delete-orphan")
|
|
dimension_scores = relationship("DimensionScore", back_populates="ticker", cascade="all, delete-orphan")
|
|
composite_scores = relationship("CompositeScore", back_populates="ticker", cascade="all, delete-orphan")
|
|
trade_setups = relationship("TradeSetup", back_populates="ticker", cascade="all, delete-orphan")
|
|
watchlist_entries = relationship("WatchlistEntry", back_populates="ticker", cascade="all, delete-orphan")
|
|
ingestion_progress = relationship("IngestionProgress", back_populates="ticker", cascade="all, delete-orphan", uselist=False)
|