rebuild(screener): add controlled formulas and rolling backtests

This commit is contained in:
leefer
2026-07-30 10:45:40 +08:00
parent 08f69b0641
commit b79b4ba280
21 changed files with 616 additions and 37 deletions
+15
View File
@@ -15,6 +15,8 @@ from backend.features.accounts.auth import (
)
from backend.features.screener.schemas import (
CustomStrategyInput,
FormulaCompileInput,
FormulaCompileResponse,
IdentifierResponse,
MessageResponse,
ScreenerCatalogResponse,
@@ -24,6 +26,7 @@ from backend.features.screener.schemas import (
)
from backend.features.screener.service import ScreenerError
from backend.http.errors import AppError
from backend.llm.gateway import LLMGatewayError
router = APIRouter(prefix="/screener", tags=["screener"])
@@ -60,6 +63,15 @@ def save_custom(
return _call(request, "save_custom", principal.user.id, payload.name, payload.formula)
@router.post("/formula/compile", response_model=FormulaCompileResponse)
def compile_formula(
payload: FormulaCompileInput,
request: Request,
principal: SmartWritePrincipal,
) -> dict:
return _call(request, "compile_formula", principal, payload.description)
@router.delete("/custom/{strategy_id}", response_model=MessageResponse)
def delete_custom(
request: Request,
@@ -110,3 +122,6 @@ def _call(request: Request, method: str, *args):
return getattr(request.app.state.container.screener, method)(*args)
except (ScreenerError, MarketDataUnavailable, ProviderError, DataQualityError) as exc:
raise AppError("screener_unavailable", str(exc), 409) from exc
except LLMGatewayError as exc:
status = 403 if exc.code in {"membership_required", "quota_exhausted"} else 503
raise AppError(exc.code, str(exc), status) from exc