From 7c05359bccfa0ca50a8f55c1a99cfadd731c8e89 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Wed, 1 Apr 2026 18:06:25 +0900 Subject: fix: resolve final 3 issues for production readiness - Fix API strategies endpoint path resolution (use STRATEGIES_DIR env var) - Add DATABASE_URL env var override in alembic env.py - Move risk config fields to shared Settings base class - Remove duplicate fields from ExecutorConfig --- services/api/src/trading_api/routers/strategies.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'services/api/src/trading_api/routers') diff --git a/services/api/src/trading_api/routers/strategies.py b/services/api/src/trading_api/routers/strategies.py index e968529..7ddd54e 100644 --- a/services/api/src/trading_api/routers/strategies.py +++ b/services/api/src/trading_api/routers/strategies.py @@ -1,15 +1,26 @@ """Strategy endpoints.""" import logging +import os import sys from pathlib import Path from fastapi import APIRouter, HTTPException -# Add strategy-engine to path for plugin loading -_STRATEGY_DIR = Path(__file__).resolve().parents[5] / "strategy-engine" -if str(_STRATEGY_DIR) not in sys.path: - sys.path.insert(0, str(_STRATEGY_DIR)) +# Resolve strategies directory from env or relative paths +_STRATEGIES_DIR = Path( + os.environ.get( + "STRATEGIES_DIR", + str(Path(__file__).resolve().parents[5] / "services" / "strategy-engine" / "strategies"), + ) +) +# Add parent so `from strategies.base import BaseStrategy` works +if str(_STRATEGIES_DIR.parent) not in sys.path: + sys.path.insert(0, str(_STRATEGIES_DIR.parent)) +# Add strategy-engine src for plugin_loader +_SE_SRC = Path(__file__).resolve().parents[5] / "services" / "strategy-engine" / "src" +if str(_SE_SRC) not in sys.path: + sys.path.insert(0, str(_SE_SRC)) logger = logging.getLogger(__name__) @@ -22,8 +33,7 @@ async def list_strategies(): try: from strategy_engine.plugin_loader import load_strategies - strategies_dir = _STRATEGY_DIR / "strategies" - strategies = load_strategies(strategies_dir) + strategies = load_strategies(_STRATEGIES_DIR) return [ { "name": s.name, -- cgit v1.2.3