Files
Mutual_Fund/repositories/portfolio_benchmark.py

39 lines
1.3 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.
"""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()
)
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)
)