done
This commit is contained in:
@@ -18,9 +18,21 @@ from app.database import Base
|
||||
|
||||
|
||||
def utcnow() -> datetime:
|
||||
"""Naive UTC datetime. All datetimes in this codebase are stored as naive-UTC."""
|
||||
return datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
|
||||
def iso_utc(dt: Optional[datetime]) -> Optional[str]:
|
||||
"""Serialize a naive-UTC datetime to an explicit ISO-8601 UTC string (suffix 'Z').
|
||||
If dt already carries tzinfo, convert to UTC first. Returns None if dt is None."""
|
||||
if dt is None:
|
||||
return None
|
||||
if dt.tzinfo is not None:
|
||||
dt = dt.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
# Drop microseconds past millisecond for compactness; always end in Z
|
||||
return dt.isoformat(timespec="milliseconds") + "Z"
|
||||
|
||||
|
||||
class Post(Base):
|
||||
__tablename__ = "posts"
|
||||
|
||||
@@ -39,6 +51,8 @@ class Post(Base):
|
||||
price_at_post: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
|
||||
signal: Mapped[Optional[str]] = mapped_column(String(8), nullable=True)
|
||||
ai_reasoning: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
prefilter_reason: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
|
||||
analysis_version: Mapped[Optional[str]] = mapped_column(String(16), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=utcnow)
|
||||
|
||||
trades: Mapped[List["BotTrade"]] = relationship("BotTrade", back_populates="trigger_post")
|
||||
@@ -89,3 +103,10 @@ class Subscription(Base):
|
||||
active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
subscribed_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=utcnow)
|
||||
|
||||
# Per-user trading config (null → use platform defaults)
|
||||
leverage: Mapped[int] = mapped_column(Integer, nullable=False, default=3)
|
||||
position_size_usd: Mapped[float] = mapped_column(Float, nullable=False, default=20.0)
|
||||
take_profit_pct: Mapped[Optional[float]] = mapped_column(Float, nullable=True) # e.g. 2.0 = close at +2%
|
||||
stop_loss_pct: Mapped[Optional[float]] = mapped_column(Float, nullable=True) # e.g. 1.5 = close at -1.5%
|
||||
min_confidence: Mapped[int] = mapped_column(Integer, nullable=False, default=80)
|
||||
|
||||
Reference in New Issue
Block a user