Files
qlib/backend/app/domain/repositories/selection.py
T
Simon 995ed08548 feat(chart): M9-1 Chart DTO + Chart Service + Chart API(v3 §20)
- domain/entities/chart.py:ChartResult/OHLC/Volume/Series/EventMarker/ChartMetadata
  (adjust_mode + execution_price_basis 口径元数据)+ SelectionHit
- application/services/chart_service.py:个股 K线/量/MA 指标;显示层 qfq/hfq 折算
  (基于主口径 none 行情 × adjust_factor,绝回写研究数据);回测个股视图把实际成交
  转 fills 标记并在显示口径不同时做坐标换算(v3 §20.3/§20.5)
- by-symbol 历史查询:SignalRepository/SelectionRepository.list_by_symbol(含溯源 id)
- api/charts.py:/stocks/{symbol}/chart|signals|selections、/backtests/{id}/stocks/{symbol}/chart
  |trades|positions
- tests/test_charts.py(指标/qfq-hfq 折算断言/回测 fills/API 集成+404);全量 pytest 通过
2026-09-09 07:09:52 +08:00

34 lines
1.3 KiB
Python
Raw 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.
"""选股 Repository Protocol(M6.3 落库)。
业务层只依赖本 Protocol;实现位于 infrastructure/persistence。
结果按 v2 §8:selection_snapshot(一次运行的查询与统计)+ selection_result(逐候选行),
用于回答「2023-08-15 为什么选这只股票」「某日选了什么」。
"""
from __future__ import annotations
from datetime import date
from typing import Protocol
from app.domain.entities.chart import SelectionHit
from app.domain.entities.selection import SelectionMeta, SelectionResult
class SelectionRepository(Protocol):
def save(self, selection_id: str, result: SelectionResult) -> None:
"""落库一次选股:snapshot 一行 + 候选逐行(同一事务,由调用方 commit)。"""
def get(self, selection_id: str) -> SelectionResult | None:
"""按 id 读回完整结果(重建 SelectionResult)。"""
def list_recent(
self,
as_of: date | None = None,
method: str | None = None,
limit: int = 20,
) -> list[SelectionMeta]:
"""历史选股元数据列表(按 created_at 倒序;可选 as_of/method 过滤)。"""
def list_by_symbol(self, symbol: str, limit: int = 50) -> list[SelectionHit]:
"""该股在历史选股中的命中(Chart 标记用,含 as_of/rank/reason)。"""