|
|
from app.database import Base
|
|
|
from sqlalchemy import Column, Integer, String, Float, DateTime, BigInteger, Boolean, Text, Index
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
class ContractInfo(Base):
|
|
|
"""期货合约信息表"""
|
|
|
__tablename__ = "contract_info"
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
symbol = Column(String(20), unique=True, nullable=False, comment="合约代码,如 rb2401")
|
|
|
exchange = Column(String(10), nullable=False, comment="交易所代码: SHFE/DCE/CZCE/INE/CFFEX")
|
|
|
name = Column(String(50), comment="合约名称")
|
|
|
product = Column(String(20), comment="品种代码,如 rb")
|
|
|
multiplier = Column(Integer, default=10, comment="合约乘数")
|
|
|
price_tick = Column(Float, comment="最小变动价位")
|
|
|
limit_up_ratio = Column(Float, comment="涨停板比例")
|
|
|
limit_down_ratio = Column(Float, comment="跌停板比例")
|
|
|
expire_date = Column(DateTime, comment="到期日")
|
|
|
is_active = Column(Boolean, default=True, comment="是否活跃")
|
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
|
|
__table_args__ = (
|
|
|
Index("idx_contract_product", "product"),
|
|
|
Index("idx_contract_exchange", "exchange"),
|
|
|
)
|
|
|
|
|
|
|
|
|
class KlineDaily(Base):
|
|
|
"""日K线表"""
|
|
|
__tablename__ = "kline_daily"
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
symbol = Column(String(20), nullable=False)
|
|
|
trade_date = Column(DateTime, nullable=False)
|
|
|
open = Column(Float)
|
|
|
high = Column(Float)
|
|
|
low = Column(Float)
|
|
|
close = Column(Float)
|
|
|
volume = Column(BigInteger, comment="成交量")
|
|
|
turnover = Column(Float, comment="成交额")
|
|
|
open_interest = Column(BigInteger, comment="持仓量")
|
|
|
settle = Column(Float, comment="结算价")
|
|
|
pre_settle = Column(Float, comment="昨结算")
|
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
|
|
__table_args__ = (
|
|
|
Index("idx_kline_daily_symbol_date", "symbol", "trade_date", unique=True),
|
|
|
)
|
|
|
|
|
|
|
|
|
class KlineWeekly(Base):
|
|
|
"""周K线表"""
|
|
|
__tablename__ = "kline_weekly"
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
symbol = Column(String(20), nullable=False)
|
|
|
trade_date = Column(DateTime, nullable=False, comment="周最后一天")
|
|
|
open = Column(Float)
|
|
|
high = Column(Float)
|
|
|
low = Column(Float)
|
|
|
close = Column(Float)
|
|
|
volume = Column(BigInteger)
|
|
|
turnover = Column(Float)
|
|
|
open_interest = Column(BigInteger)
|
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
|
|
__table_args__ = (
|
|
|
Index("idx_kline_weekly_symbol_date", "symbol", "trade_date", unique=True),
|
|
|
)
|
|
|
|
|
|
|
|
|
class KlineIntraday(Base):
|
|
|
"""分钟级K线表(5m/15m/30m/60m共用,通过period区分)"""
|
|
|
__tablename__ = "kline_intraday"
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
symbol = Column(String(20), nullable=False)
|
|
|
period = Column(String(10), nullable=False, comment="周期: 5m/15m/30m/60m")
|
|
|
trade_time = Column(DateTime, nullable=False)
|
|
|
open = Column(Float)
|
|
|
high = Column(Float)
|
|
|
low = Column(Float)
|
|
|
close = Column(Float)
|
|
|
volume = Column(BigInteger)
|
|
|
turnover = Column(Float)
|
|
|
open_interest = Column(BigInteger)
|
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
|
|
__table_args__ = (
|
|
|
Index("idx_kline_intraday_symbol_period_time", "symbol", "period", "trade_time", unique=True),
|
|
|
)
|
|
|
|
|
|
|
|
|
class DataSourceConfig(Base):
|
|
|
"""数据源配置表"""
|
|
|
__tablename__ = "data_source_config"
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
source_name = Column(String(30), unique=True, nullable=False, comment="数据源名称: tushare/ctp")
|
|
|
display_name = Column(String(50), comment="显示名称")
|
|
|
is_enabled = Column(Boolean, default=False, comment="是否启用")
|
|
|
config_json = Column(Text, comment="JSON格式的配置信息")
|
|
|
priority = Column(Integer, default=0, comment="优先级,数字越小优先级越高")
|
|
|
last_sync_time = Column(DateTime, comment="最后同步时间")
|
|
|
status = Column(String(20), default="unknown", comment="状态: ok/error/unknown")
|
|
|
error_msg = Column(Text, comment="错误信息")
|
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|