功能细节优化

This commit is contained in:
2026-06-15 01:26:39 +08:00
parent e524a3589a
commit 964c17c200
33 changed files with 6990 additions and 210 deletions

View File

@@ -1,4 +1,4 @@
"""数据中台 ORM 模型SQLAlchemy 2.0)。"""
"""数据中台 ORM 模型SQLAlchemy 2.0)。"""
from __future__ import annotations
import datetime as dt
@@ -64,6 +64,21 @@ class SectorDaily(Base):
leader: Mapped[str] = mapped_column(String(40), default="")
class SectorLeader(Base):
"""板块每日龙头股前5按成交额"""
__tablename__ = "sector_leaders"
__table_args__ = (UniqueConstraint("date", "sector", "code", name="uq_sector_leader"),)
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
date: Mapped[dt.date] = mapped_column(Date, index=True)
sector: Mapped[str] = mapped_column(String(40), index=True)
code: Mapped[str] = mapped_column(String(12))
name: Mapped[str] = mapped_column(String(40))
pct: Mapped[float] = mapped_column(Float, default=0.0)
price: Mapped[float] = mapped_column(Float, default=0.0)
amount: Mapped[float] = mapped_column(Float, default=0.0)
rank: Mapped[int] = mapped_column(Integer, default=0)
class FundFlowDaily(Base):
"""行业资金流每日快照。"""
__tablename__ = "fund_flow_daily"
@@ -349,3 +364,68 @@ class IntradayEvent(Base):
description: Mapped[str] = mapped_column(String(200), default="")
detected_at: Mapped[dt.datetime] = mapped_column(DateTime, server_default=func.now(), index=True)
notified: Mapped[bool] = mapped_column(default=False)
class PaperAccount(Base):
"""模拟盘账户。"""
__tablename__ = "paper_accounts"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(50), default="默认模拟盘")
initial_cash: Mapped[float] = mapped_column(Float, default=1_000_000.0)
cash: Mapped[float] = mapped_column(Float, default=1_000_000.0)
is_active: Mapped[bool] = mapped_column(default=True)
created_at: Mapped[dt.datetime] = mapped_column(DateTime, server_default=func.now())
class PaperTrade(Base):
"""模拟盘交易记录。"""
__tablename__ = "paper_trades"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
account_id: Mapped[int] = mapped_column(Integer, index=True, default=1)
date: Mapped[dt.date] = mapped_column(Date, index=True)
code: Mapped[str] = mapped_column(String(12), index=True)
name: Mapped[str] = mapped_column(String(40), default="")
side: Mapped[str] = mapped_column(String(4)) # buy / sell
price: Mapped[float] = mapped_column(Float)
qty: Mapped[int] = mapped_column(Integer)
fee: Mapped[float] = mapped_column(Float, default=0.0)
cash_before: Mapped[float] = mapped_column(Float, default=0.0)
cash_after: Mapped[float] = mapped_column(Float, default=0.0)
reason: Mapped[str] = mapped_column(String(60), default="")
created_at: Mapped[dt.datetime] = mapped_column(DateTime, server_default=func.now())
class User(Base):
"""用户表(用于鉴权)。"""
__tablename__ = "users"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
username: Mapped[str] = mapped_column(String(50), unique=True, index=True)
hashed_password: Mapped[str] = mapped_column(String(100))
is_admin: Mapped[bool] = mapped_column(default=False)
is_active: Mapped[bool] = mapped_column(default=True)
created_at: Mapped[dt.datetime] = mapped_column(DateTime, server_default=func.now())
class WatchlistGroup(Base):
"""自选股分组。"""
__tablename__ = "watchlist_groups"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(50))
description: Mapped[str] = mapped_column(String(200), default="")
color: Mapped[str] = mapped_column(String(20), default="blue") # 分组颜色标识
sort_order: Mapped[int] = mapped_column(Integer, default=0)
is_default: Mapped[bool] = mapped_column(default=False)
created_at: Mapped[dt.datetime] = mapped_column(DateTime, server_default=func.now())
class WatchlistItem(Base):
"""自选股项目。"""
__tablename__ = "watchlist_items"
__table_args__ = (UniqueConstraint("group_id", "code", name="uq_watchlist_group_code"),)
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
group_id: Mapped[int] = mapped_column(Integer, index=True)
code: Mapped[str] = mapped_column(String(12), index=True)
name: Mapped[str] = mapped_column(String(40), default="")
sort_order: Mapped[int] = mapped_column(Integer, default=0)
note: Mapped[str] = mapped_column(String(200), default="") # 个股备注
added_at: Mapped[dt.datetime] = mapped_column(DateTime, server_default=func.now())