26 lines
958 B
Python
26 lines
958 B
Python
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import DateTime, Float, Integer, String, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from database import Base
|
|
|
|
|
|
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)
|
|
)
|