as-event/backend/app/schemas.py

66 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""API 请求/响应模型pydantic v2"""
from __future__ import annotations
from datetime import date, datetime
from typing import List, Optional
from pydantic import BaseModel, Field
# ---------------- 事件 ----------------
class EventIn(BaseModel):
event_date: date
title: str = Field(min_length=1, max_length=255)
category: str = "其他"
impact_direction: str = "neutral" # bullish/bearish/neutral
severity: int = Field(default=3, ge=1, le=5)
related_indices: Optional[str] = None # CSV如 "000001.SH,399006.SZ"
cycle_tag: str = "none" # top/bottom/none
description: Optional[str] = None
source_url: Optional[str] = None
class EventOut(EventIn):
id: int
source: str = "manual"
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
model_config = {"from_attributes": True}
# ---------------- ETF ----------------
class EtfFlowIn(BaseModel):
trade_date: date
etf_code: str = ""
etf_name: Optional[str] = None
category: Optional[str] = None
related_index: Optional[str] = None
net_inflow: Optional[float] = None # 亿元
shares_change: Optional[float] = None
note: Optional[str] = None
class EtfFlowOut(EtfFlowIn):
id: int
source: str = "manual"
created_at: Optional[datetime] = None
model_config = {"from_attributes": True}
# ---------------- 顶底人工标注 ----------------
class AnnotationIn(BaseModel):
index_code: str
anno_date: date
kind: str = "watch" # top/bottom/watch
note: Optional[str] = None
# ---------------- 导入结果 ----------------
class ImportResult(BaseModel):
inserted: int
updated: int
total: int
errors: List[str] = []