142 lines
5.7 KiB
Python
142 lines
5.7 KiB
Python
from datetime import datetime
|
|
from uuid import uuid4
|
|
|
|
from sqlalchemy import DateTime, Float, Index, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from tradingagents.database.base import Base
|
|
|
|
|
|
class StockPrice(Base):
|
|
__tablename__ = "stock_prices"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid4())
|
|
)
|
|
ticker: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
date: Mapped[str] = mapped_column(String(10), nullable=False)
|
|
open: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
high: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
low: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
close: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
adj_close: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
volume: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
data_source: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index("ix_stock_prices_ticker_date", "ticker", "date", unique=True),
|
|
)
|
|
|
|
|
|
class TechnicalIndicator(Base):
|
|
__tablename__ = "technical_indicators"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid4())
|
|
)
|
|
ticker: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
date: Mapped[str] = mapped_column(String(10), nullable=False)
|
|
indicator_name: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
indicator_value: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index(
|
|
"ix_tech_indicators_ticker_date_name",
|
|
"ticker",
|
|
"date",
|
|
"indicator_name",
|
|
unique=True,
|
|
),
|
|
)
|
|
|
|
|
|
class NewsArticle(Base):
|
|
__tablename__ = "news_articles"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid4())
|
|
)
|
|
ticker: Mapped[str | None] = mapped_column(String(20), nullable=True, index=True)
|
|
headline: Mapped[str] = mapped_column(String(500), nullable=False)
|
|
source: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
url: Mapped[str | None] = mapped_column(String(1000), nullable=True)
|
|
summary: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
content: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
published_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
sentiment_score: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
data_source: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
|
|
class SocialMediaPost(Base):
|
|
__tablename__ = "social_media_posts"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid4())
|
|
)
|
|
ticker: Mapped[str | None] = mapped_column(String(20), nullable=True, index=True)
|
|
platform: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
post_id: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
author: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
content: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
engagement_score: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
sentiment_score: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
posted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
data_source: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
|
|
class FundamentalData(Base):
|
|
__tablename__ = "fundamental_data"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid4())
|
|
)
|
|
ticker: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
report_date: Mapped[str] = mapped_column(String(10), nullable=False)
|
|
metric_name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
metric_value: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
metric_unit: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
|
data_source: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index(
|
|
"ix_fundamental_ticker_date_metric",
|
|
"ticker",
|
|
"report_date",
|
|
"metric_name",
|
|
unique=True,
|
|
),
|
|
)
|
|
|
|
|
|
class DataCache(Base):
|
|
__tablename__ = "data_cache"
|
|
|
|
id: Mapped[str] = mapped_column(
|
|
String(36), primary_key=True, default=lambda: str(uuid4())
|
|
)
|
|
cache_key: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
|
data_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
ticker: Mapped[str | None] = mapped_column(String(20), nullable=True, index=True)
|
|
date_range_start: Mapped[str | None] = mapped_column(String(10), nullable=True)
|
|
date_range_end: Mapped[str | None] = mapped_column(String(10), nullable=True)
|
|
cached_data: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
expires_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=datetime.utcnow, nullable=False
|
|
)
|