feat(strategy): M8.3 策略模型 + /api/strategies(命名配置资产,可展开为 ResearchSpec)

- StrategyDefinition:universe/factors/selection/rebalance/costs/portfolio +
  price_adjustment(除 period 外完整策略定义);to_research_spec(period) 展开为标准 Spec
- strategy 表(migration e1f2a3b4c5d6,MySQL 已应用;name 唯一)+ StrategyRepository
- /api/strategies:POST/GET/DELETE + POST /{id}/expand(period+initial_capital → ResearchSpec)
- tests/test_strategies.py(repo CRUD/同名/expand、API CRUD/400/404);全量 pytest 通过
This commit is contained in:
Simon
2026-09-09 00:38:09 +08:00
parent 692bdb3be5
commit 9d25d466e5
10 changed files with 436 additions and 0 deletions
@@ -0,0 +1,20 @@
"""策略 Repository Protocol(M8.3)。"""
from __future__ import annotations
from typing import Protocol
from app.domain.entities.strategy import StrategyDefinition
class StrategyRepository(Protocol):
def save(self, definition: StrategyDefinition) -> StrategyDefinition:
"""新建(name 冲突抛 ValueError)。"""
def get(self, strategy_id: str) -> StrategyDefinition | None: ...
def get_by_name(self, name: str) -> StrategyDefinition | None: ...
def list(self) -> list[StrategyDefinition]: ...
def delete(self, strategy_id: str) -> bool: ...