qnloft-stock/DB/model/StockDaily.py

59 lines
2.3 KiB
Python
Raw Normal View History

2023-11-24 02:49:22 +00:00
# 定义表格映射类
# 定义表格映射类
from sqlalchemy import Column, Integer, String, Float
from sqlalchemy.orm import declarative_base
def get_stock_daily(table_name):
class StockDaily(declarative_base()):
__tablename__ = table_name
id = Column(Integer, primary_key=True, autoincrement=True)
ts_code = Column(String, nullable=False) # ts代码
trade_date = Column(String, nullable=False) # 交易日期
crncy_code = Column(String) # 货币代码
pre_close = Column(Float) # 昨收盘价(元)
open = Column(Float) # 开盘价(元)
high = Column(Float) # 最高价(元)
low = Column(Float) # 最低价(元)
close = Column(Float) # 收盘价(元)
change = Column(Float) # 涨跌(元)
pct_chg = Column(Float) # 涨跌幅(%)
volume = Column(Float) # 成交量(手)
amount = Column(Float) # 成交金额(千元)
adj_pre_close = Column(Float) # 复权昨收盘价(元)
adj_open = Column(Float) # 复权开盘价(元)
adj_high = Column(Float) # 复权最高价(元)
adj_low = Column(Float) # 复权最低价(元)
adj_close = Column(Float) # 复权收盘价(元)
adj_factor = Column(Float) # 复权因子
avg_price = Column(Float) # 均价(VWAP)
trade_status = Column(String) # 交易状态
turnover_rate = Column(Float) # 换手率
turnover_rate_f = Column(Float) # 换手率(自由流通股)
volume_ratio = Column(Float) # 量比
pe = Column(Float) # 市盈率(总市值/净利润)
pe_ttm = Column(Float) # 市盈率TTM
pb = Column(Float) # 市净率(总市值/净资产)
ps = Column(Float) # 市销率
ps_ttm = Column(Float) # 市销率TTM
dv_ratio = Column(Float) # 股息率
dv_ttm = Column(Float) # 滚动股息率
total_share = Column(Float) # 总股本
float_share = Column(Float) # 流通股本
free_share = Column(Float) # 自由流通股本
total_mv = Column(Float) # 总市值
circ_mv = Column(Float) # 流通市值
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return f"<StockDaily(ts_code='{self.ts_code}', trade_date='{self.trade_date}', close='{self.close}')>"
def to_dict(self):
return {"ts_code": self.ts_code, "trade_date": self.trade_date, "pre_close": self.pre_close,
"turnover_rate": self.turnover_rate}
return StockDaily