diff options
Diffstat (limited to 'services/api/src/trading_api/routers/strategies.py')
| -rw-r--r-- | services/api/src/trading_api/routers/strategies.py | 22 |
1 files changed, 16 insertions, 6 deletions
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, |
