diff --git a/src/zvt/broker/qmt/qmt_quote.py b/src/zvt/broker/qmt/qmt_quote.py index dc1610d2..831290f6 100644 --- a/src/zvt/broker/qmt/qmt_quote.py +++ b/src/zvt/broker/qmt/qmt_quote.py @@ -8,7 +8,7 @@ from zvt.contract import IntervalLevel, AdjustType from zvt.contract.api import decode_entity_id, df_to_db, get_db_session -from zvt.domain import StockQuote, Stock +from zvt.domain import StockQuote, Stock, Stock1dKdata from zvt.domain.quotes.stock.stock_quote import Stock1mQuote, StockQuoteLog from zvt.utils.pd_utils import pd_is_not_null from zvt.utils.time_utils import ( @@ -198,6 +198,7 @@ def on_data(datas, stock_df=entity_df): ) df = df.rename(columns={"lastPrice": "price", "amount": "turnover"}) + df["close"] = df["price"] df["timestamp"] = df["time"].apply(to_pd_timestamp) @@ -230,8 +231,11 @@ def on_data(datas, stock_df=entity_df): df["float_cap"] = df["float_volume"] * df["price"] df["total_cap"] = df["total_volume"] * df["price"] + df["provider"] = "qmt" # 实时行情统计,只保留最新 df_to_db(df, data_schema=StockQuote, provider="qmt", force_update=True, drop_duplicates=False) + df["level"] = "1d" + df_to_db(df, data_schema=Stock1dKdata, provider="qmt", force_update=True, drop_duplicates=False) # 1分钟分时 df["id"] = df[["entity_id", "timestamp"]].apply( diff --git a/src/zvt/domain/quotes/stock/stock_quote.py b/src/zvt/domain/quotes/stock/stock_quote.py index eee3d045..2146c6db 100644 --- a/src/zvt/domain/quotes/stock/stock_quote.py +++ b/src/zvt/domain/quotes/stock/stock_quote.py @@ -4,25 +4,17 @@ from zvt.contract import Mixin from zvt.contract.register import register_schema +from zvt.domain import StockKdataCommon StockQuoteBase = declarative_base() -class StockQuote(StockQuoteBase, Mixin): +class StockQuote(StockQuoteBase, StockKdataCommon): __tablename__ = "stock_quote" - code = Column(String(length=32)) - name = Column(String(length=32)) - #: UNIX时间戳 time = Column(Integer) #: 最新价 price = Column(Float) - # 涨跌幅 - change_pct = Column(Float) - # 成交金额 - turnover = Column(Float) - # 换手率 - turnover_rate = Column(Float) #: 是否涨停 is_limit_up = Column(Boolean) #: 封涨停金额 @@ -41,21 +33,12 @@ class StockQuote(StockQuoteBase, Mixin): total_cap = Column(Float) -class StockQuoteLog(StockQuoteBase, Mixin): +class StockQuoteLog(StockQuoteBase, StockKdataCommon): __tablename__ = "stock_quote_log" - code = Column(String(length=32)) - name = Column(String(length=32)) - #: UNIX时间戳 time = Column(Integer) #: 最新价 price = Column(Float) - # 涨跌幅 - change_pct = Column(Float) - # 成交金额 - turnover = Column(Float) - # 换手率 - turnover_rate = Column(Float) #: 是否涨停 is_limit_up = Column(Boolean) #: 封涨停金额 diff --git a/src/zvt/tag/tag_models.py b/src/zvt/tag/tag_models.py index 710a1b19..0db0fd5b 100644 --- a/src/zvt/tag/tag_models.py +++ b/src/zvt/tag/tag_models.py @@ -11,21 +11,21 @@ class TagInfoModel(MixinModel): tag: str - tag_reason: Optional[str] = None + tag_reason: Optional[str] = Field(default=None) class CreateTagInfoModel(CustomModel): tag: str - tag_reason: Optional[str] = None + tag_reason: Optional[str] = Field(default=None) class StockTagsModel(MixinModel): - main_tag: str - main_tag_reason: Optional[str] = None + main_tag: Optional[str] = Field(default=None) + main_tag_reason: Optional[str] = Field(default=None) main_tags: Dict[str, str] - sub_tag: Union[str, None] - sub_tag_reason: Optional[str] = None + sub_tag: Optional[str] = Field(default=None) + sub_tag_reason: Optional[str] = Field(default=None) sub_tags: Union[Dict[str, str], None] active_hidden_tags: Union[Dict[str, str], None] @@ -36,11 +36,11 @@ class StockTagsModel(MixinModel): class SimpleStockTagsModel(CustomModel): entity_id: str name: str - main_tag: str - main_tag_reason: Optional[str] = None + main_tag: Optional[str] = Field(default=None) + main_tag_reason: Optional[str] = Field(default=None) main_tags: Dict[str, str] sub_tag: Union[str, None] - sub_tag_reason: Optional[str] = None + sub_tag_reason: Optional[str] = Field(default=None) sub_tags: Union[Dict[str, str], None] active_hidden_tags: Union[Dict[str, str], None] @@ -56,20 +56,20 @@ class QuerySimpleStockTagsModel(CustomModel): class BatchSetStockTagsModel(CustomModel): entity_ids: List[str] tag: str - tag_reason: Optional[str] = None + tag_reason: Optional[str] = Field(default=None) tag_type: TagType class TagParameter(CustomModel): main_tag: str - main_tag_reason: Optional[str] = None - sub_tag: Optional[str] = None - sub_tag_reason: Optional[str] = None + main_tag_reason: Optional[str] = Field(default=None) + sub_tag: Optional[str] = Field(default=None) + sub_tag_reason: Optional[str] = Field(default=None) class StockTagOptions(CustomModel): - main_tag: Optional[str] = None - sub_tag: Optional[str] = None + main_tag: Optional[str] = Field(default=None) + sub_tag: Optional[str] = Field(default=None) main_tag_options: List[CreateTagInfoModel] sub_tag_options: List[CreateTagInfoModel] @@ -77,10 +77,10 @@ class StockTagOptions(CustomModel): class SetStockTagsModel(CustomModel): entity_id: str main_tag: str - main_tag_reason: Optional[str] = None - sub_tag: Optional[str] = None - sub_tag_reason: Optional[str] = None - active_hidden_tags: Optional[Dict[str, str]] = None + main_tag_reason: Optional[str] = Field(default=None) + sub_tag: Optional[str] = Field(default=None) + sub_tag_reason: Optional[str] = Field(default=None) + active_hidden_tags: Optional[Dict[str, str]] = Field(default=None) # @field_validator("main_tag") # @classmethod @@ -148,8 +148,8 @@ class CreateStockPoolsModel(CustomModel): class QueryStockTagStatsModel(CustomModel): - stock_pool_name: Optional[str] = None - entity_ids: Optional[List[str]] = None + stock_pool_name: Optional[str] = Field(default=None) + entity_ids: Optional[List[str]] = Field(default=None) query_type: Optional[TagStatsQueryType] = Field(default=TagStatsQueryType.details) @field_validator("stock_pool_name", "entity_ids") @@ -180,8 +180,8 @@ def stock_pool_name_must_be_in(cls, v: str) -> str: class StockTagDetailsModel(CustomModel): entity_id: str - main_tag: str - sub_tag: Union[str, None] + main_tag: Optional[str] = Field(default=None) + sub_tag: Optional[str] = Field(default=None) hidden_tags: Union[List[str], None] #: 代码 diff --git a/src/zvt/trading/trading_models.py b/src/zvt/trading/trading_models.py index b9b928e5..43a93976 100644 --- a/src/zvt/trading/trading_models.py +++ b/src/zvt/trading/trading_models.py @@ -133,7 +133,7 @@ class StockQuoteModel(MixinModel): #: 总市值 total_cap: float - main_tag: str = Field(default=None) + main_tag: Optional[str] = Field(default=None) sub_tag: Union[str, None] = Field(default=None) hidden_tags: Union[List[str], None] = Field(default=None)