You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.0 KiB
78 lines
3.0 KiB
|
2 months ago
|
"""
|
||
|
|
股票基础数据模型
|
||
|
|
"""
|
||
|
|
from datetime import datetime, date
|
||
|
|
from sqlalchemy import Column, Integer, BigInteger, String, Numeric, Text, Date, DateTime, ForeignKey, Boolean
|
||
|
|
from sqlalchemy.orm import relationship
|
||
|
|
from app.db.base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class StockBasic(Base):
|
||
|
|
"""股票基础数据表"""
|
||
|
|
__tablename__ = "stock_basic"
|
||
|
|
|
||
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
||
|
|
code = Column(String(20), unique=True, nullable=False, index=True)
|
||
|
|
name = Column(String(50))
|
||
|
|
total_shares = Column(BigInteger)
|
||
|
|
float_shares = Column(BigInteger)
|
||
|
|
industry_index_name = Column(String(100))
|
||
|
|
industry_index_code = Column(String(20), ForeignKey("index_basic.code"))
|
||
|
|
institution_hold_ratio = Column(Numeric(10, 4))
|
||
|
|
industry_level3 = Column(String(100))
|
||
|
|
list_date = Column(Date)
|
||
|
|
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||
|
|
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)
|
||
|
|
|
||
|
|
industry_index = relationship("IndexBasic", back_populates="stocks")
|
||
|
|
|
||
|
|
|
||
|
|
class IndexBasic(Base):
|
||
|
|
"""指数基础表"""
|
||
|
|
__tablename__ = "index_basic"
|
||
|
|
|
||
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
||
|
|
code = Column(String(20), unique=True, nullable=False, index=True)
|
||
|
|
name = Column(String(100))
|
||
|
|
component_count = Column(Integer)
|
||
|
|
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||
|
|
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)
|
||
|
|
|
||
|
|
stocks = relationship("StockBasic", back_populates="industry_index")
|
||
|
|
trades = relationship("IndexTrade", back_populates="index")
|
||
|
|
|
||
|
|
|
||
|
|
class IndexTrade(Base):
|
||
|
|
"""指数交易表"""
|
||
|
|
__tablename__ = "index_trade"
|
||
|
|
|
||
|
|
id = Column(BigInteger, primary_key=True, index=True)
|
||
|
|
index_code = Column(String(20), ForeignKey("index_basic.code"), nullable=False, index=True)
|
||
|
|
trade_date = Column(Date, nullable=False, index=True)
|
||
|
|
open = Column(Numeric(10, 3))
|
||
|
|
close = Column(Numeric(10, 3))
|
||
|
|
high = Column(Numeric(10, 3))
|
||
|
|
low = Column(Numeric(10, 3))
|
||
|
|
change_pct = Column(Numeric(10, 4))
|
||
|
|
volume = Column(BigInteger)
|
||
|
|
amount = Column(Numeric(18, 2))
|
||
|
|
total_market_value = Column(Numeric(18, 2))
|
||
|
|
float_market_value = Column(Numeric(18, 2))
|
||
|
|
up_count = Column(Integer)
|
||
|
|
down_count = Column(Integer)
|
||
|
|
flat_count = Column(Integer)
|
||
|
|
limit_up_count = Column(Integer)
|
||
|
|
limit_down_count = Column(Integer)
|
||
|
|
suspend_count = Column(Integer)
|
||
|
|
pe_ratio = Column(Numeric(10, 4))
|
||
|
|
pe_median = Column(Numeric(10, 4))
|
||
|
|
is_new_high = Column(Boolean, default=False)
|
||
|
|
is_new_low = Column(Boolean, default=False)
|
||
|
|
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||
|
|
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)
|
||
|
|
|
||
|
|
index = relationship("IndexBasic", back_populates="trades")
|
||
|
|
|
||
|
|
__table_args__ = (
|
||
|
|
{'unique_constraint': None},
|
||
|
|
)
|