from datetime import datetime from app import db, ma class Ticker_Price(db.Model): __tablename__ = 'ticker_prices' __table_args__ = {"schema": "public"} id = db.Column(db.Integer, primary_key=True, autoincrement=True) symbol = db.Column(db.String(20), nullable=False, index=True) price_decimal = db.Column(db.Numeric(10, 4), nullable=False) currency = db.Column(db.String(10), nullable=True) change_decimal = db.Column(db.Numeric(10, 4), nullable=True) percent_change_decimal = db.Column(db.Numeric(10, 4), nullable=True) timestamp = db.Column(db.TIMESTAMP(), default=datetime.utcnow, index=True) def to_dict(self): return { "symbol": self.symbol, "price": float(self.price_decimal) if self.price_decimal is not None else None, "currency": self.currency, "change": float(self.change_decimal) if self.change_decimal is not None else None, "percent_change": float(self.percent_change_decimal) if self.percent_change_decimal is not None else None, "timestamp": self.timestamp.isoformat() if self.timestamp else None, } class Ticker_Price_Schema(ma.SQLAlchemyAutoSchema): class Meta: model = Ticker_Price