功能更新
This commit is contained in:
@@ -9,7 +9,7 @@ Candle 表设计与 TimescaleDB hypertable 完全兼容:将来在目标 PG 库
|
||||
"""
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, Boolean, DateTime, Float, ForeignKey, Integer, String, UniqueConstraint
|
||||
from sqlalchemy import BigInteger, Boolean, DateTime, Float, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from .db import Base
|
||||
@@ -124,6 +124,65 @@ class DailySnapshot(Base):
|
||||
)
|
||||
|
||||
|
||||
class AdjFactor(Base):
|
||||
"""复权因子(adj_factor,Tushare 原始值;qfq/hfq 本地换算的底座)。
|
||||
|
||||
与 candles(不复权日线) 按 ts_code+trade_date 关联:
|
||||
前复权 qfq = 不复权价 × f(t) / f(latest);后复权 hfq = 不复权价 × f(t)。
|
||||
"""
|
||||
__tablename__ = "adj_factor"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
trade_date: Mapped[datetime] = mapped_column(DateTime, index=True)
|
||||
ts_code: Mapped[str] = mapped_column(String(12), index=True)
|
||||
adj_factor: Mapped[float] = mapped_column(Float)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("ts_code", "trade_date", name="uq_adj_code_date"),
|
||||
)
|
||||
|
||||
|
||||
class UserPreference(Base):
|
||||
"""用户偏好键值对(配色/复权口径/MA 周期/副图布局等,value 存 JSON 字符串)。"""
|
||||
__tablename__ = "user_preferences"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
||||
key: Mapped[str] = mapped_column(String(64))
|
||||
value_json: Mapped[str] = mapped_column(Text, default="null")
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, default=_utcnow, onupdate=_utcnow)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "key", name="uq_user_pref_key"),
|
||||
)
|
||||
|
||||
|
||||
class WatchlistItem(Base):
|
||||
"""自选股(星标置顶)。"""
|
||||
__tablename__ = "watchlist_items"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
||||
ts_code: Mapped[str] = mapped_column(String(12), index=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=_utcnow)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "ts_code", name="uq_watch_user_code"),
|
||||
)
|
||||
|
||||
|
||||
class ScreenerQuery(Base):
|
||||
"""自然语言选股提问历史(文本 + 解析出的条件,便于一键重跑)。"""
|
||||
__tablename__ = "screener_queries"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
||||
text: Mapped[str] = mapped_column(String(500))
|
||||
conditions_json: Mapped[str | None] = mapped_column(Text)
|
||||
hit_count: Mapped[int | None] = mapped_column(Integer)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=_utcnow, index=True)
|
||||
|
||||
|
||||
class TradeCalendar(Base):
|
||||
"""交易日历缓存(trade_cal 拉取一次宽范围后本地维护,低积分 token 限频 1 次/小时)。"""
|
||||
__tablename__ = "trade_calendar"
|
||||
|
||||
Reference in New Issue
Block a user