feat: add PriceHistory model for storing exchange price data

This commit is contained in:
counterweight 2025-12-22 15:42:11 +01:00
parent 0957d88785
commit 7339858a02
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -376,3 +376,23 @@ class RandomNumberOutcome(Base):
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(UTC)
)
class PriceHistory(Base):
"""Price history records from external exchanges."""
__tablename__ = "price_history"
__table_args__ = (
UniqueConstraint("source", "pair", "timestamp", name="uq_price_source_pair_ts"),
)
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
source: Mapped[str] = mapped_column(String(50), nullable=False, index=True)
pair: Mapped[str] = mapped_column(String(20), nullable=False)
price: Mapped[float] = mapped_column(Float, nullable=False)
timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, index=True
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=lambda: datetime.now(UTC)
)