Files
Mutual_Fund/repositories/portfolio_benchmark.py
T

39 lines
1.3 KiB
Python
Raw Normal View History

2026-09-12 20:42:33 +08:00
"""portfolio_benchmark 组合基准仓储(工作台只读:标准策略库展示)。"""
from __future__ import annotations
from sqlalchemy import select
from model.portfolio_benchmark import PortfolioBenchmark
from repositories.base import BaseRepository
# 启用态(DDL:status 启用/停用)
_ACTIVE_STATUS = "启用"
class PortfolioBenchmarkRepo(BaseRepository):
model = PortfolioBenchmark
async def list_enabled(self) -> list[PortfolioBenchmark]:
"""取全部启用态基准(标准化策略库,投顾只读不可改)。"""
return list(
(
await self.db.scalars(
select(PortfolioBenchmark).where(
PortfolioBenchmark.status == _ACTIVE_STATUS
)
)
).all()
)
2026-09-13 16:19:24 +08:00
async def get_active_by_risk(self, risk_level: str) -> PortfolioBenchmark | None:
"""Return the enabled benchmark used by the Agent rebalance flow."""
return await self.db.scalar(
select(PortfolioBenchmark)
.where(
PortfolioBenchmark.status == _ACTIVE_STATUS,
PortfolioBenchmark.risk_level == risk_level,
)
.order_by(PortfolioBenchmark.id.desc())
.limit(1)
)