90 lines
4.0 KiB
Python
90 lines
4.0 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Float, Integer, String, Text
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class AlertRecord(Base):
|
|
__tablename__ = "alerts"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
symbol: Mapped[str] = mapped_column(String(32), index=True)
|
|
chain: Mapped[str] = mapped_column(String(32), index=True)
|
|
trigger_types: Mapped[str] = mapped_column(String(255))
|
|
score: Mapped[float] = mapped_column(Float)
|
|
details_json: Mapped[str] = mapped_column(Text)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
|
|
|
|
class RuntimeLog(Base):
|
|
__tablename__ = "runtime_logs"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
level: Mapped[str] = mapped_column(String(12), index=True)
|
|
message: Mapped[str] = mapped_column(Text)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
|
|
|
|
class KvStore(Base):
|
|
"""Simple key-value settings persisted in SQLite (e.g. chart bar from web UI)."""
|
|
|
|
__tablename__ = "kv_store"
|
|
|
|
key: Mapped[str] = mapped_column(String(64), primary_key=True)
|
|
value: Mapped[str] = mapped_column(Text)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
|
|
|
|
class KeyMonitor(Base):
|
|
"""人工录入的关键位突破监控(活跃)。"""
|
|
|
|
__tablename__ = "key_monitors"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
symbol: Mapped[str] = mapped_column(String(32), index=True)
|
|
inst_id: Mapped[str] = mapped_column(String(48), index=True)
|
|
monitor_type: Mapped[str] = mapped_column(String(32))
|
|
direction: Mapped[str] = mapped_column(String(8))
|
|
upper: Mapped[float] = mapped_column(Float)
|
|
lower: Mapped[float] = mapped_column(Float)
|
|
sl_tp_mode: Mapped[str] = mapped_column(String(24), default="standard")
|
|
manual_take_profit: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
stop_outside_pct: Mapped[float] = mapped_column(Float, default=0.3)
|
|
breakeven_enabled: Mapped[int] = mapped_column(Integer, default=0)
|
|
note: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
|
|
|
|
class KeyMonitorHistory(Base):
|
|
"""已结案的关键位(可导出复盘)。"""
|
|
|
|
__tablename__ = "key_monitor_history"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
key_monitor_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
symbol: Mapped[str] = mapped_column(String(32), index=True)
|
|
inst_id: Mapped[str] = mapped_column(String(48))
|
|
monitor_type: Mapped[str] = mapped_column(String(32))
|
|
direction: Mapped[str] = mapped_column(String(8))
|
|
upper: Mapped[float] = mapped_column(Float)
|
|
lower: Mapped[float] = mapped_column(Float)
|
|
sl_tp_mode: Mapped[str] = mapped_column(String(24))
|
|
manual_take_profit: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
stop_outside_pct: Mapped[float] = mapped_column(Float)
|
|
confirm_close: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
planned_sl: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
planned_tp: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
planned_rr: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
executor_signal_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
executor_status: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
checks_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
last_alert_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
close_reason: Mapped[str] = mapped_column(String(48), index=True)
|
|
closed_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|