Files
2026-05-26 11:04:27 -04:00

75 lines
3.1 KiB
Python

from datetime import datetime
from sqlalchemy import String, Float, Integer, Boolean, DateTime, Text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class WatchlistItem(Base):
__tablename__ = "watchlist_items"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
symbol: Mapped[str] = mapped_column(String(20), nullable=False)
name: Mapped[str] = mapped_column(String(100), default="")
group_name: Mapped[str] = mapped_column(String(50), default="Default")
added_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class PortfolioPosition(Base):
__tablename__ = "portfolio_positions"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
symbol: Mapped[str] = mapped_column(String(20), nullable=False)
shares: Mapped[float] = mapped_column(Float, default=0.0)
avg_cost: Mapped[float] = mapped_column(Float, default=0.0)
broker: Mapped[str] = mapped_column(String(30), default="manual")
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class Alert(Base):
__tablename__ = "alerts"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
symbol: Mapped[str] = mapped_column(String(20), nullable=False)
alert_type: Mapped[str] = mapped_column(String(20), nullable=False) # price_above, price_below, volume_spike
target_value: Mapped[float] = mapped_column(Float, nullable=False)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
triggered_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class Setting(Base):
__tablename__ = "settings"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
key: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
value: Mapped[str] = mapped_column(Text, default="")
class NewsCache(Base):
__tablename__ = "news_cache"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
symbol: Mapped[str] = mapped_column(String(20), nullable=False)
title: Mapped[str] = mapped_column(Text, nullable=False)
description: Mapped[str] = mapped_column(Text, default="")
url: Mapped[str] = mapped_column(Text, default="")
source: Mapped[str] = mapped_column(String(100), default="")
published_at: Mapped[str] = mapped_column(String(50), default="")
sentiment: Mapped[str] = mapped_column(String(20), default="")
fetched_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
class QuoteCache(Base):
__tablename__ = "quote_cache"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
symbol: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
price: Mapped[float] = mapped_column(Float, default=0.0)
change: Mapped[float] = mapped_column(Float, default=0.0)
change_pct: Mapped[float] = mapped_column(Float, default=0.0)
volume: Mapped[int] = mapped_column(Integer, default=0)
fetched_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)