diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 18:06:25 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 18:06:25 +0900 |
| commit | 7c05359bccfa0ca50a8f55c1a99cfadd731c8e89 (patch) | |
| tree | e6d182f6ce6c32b6d53aefa5d2cd7677e154e3eb /services/api/src/trading_api/routers/strategies.py | |
| parent | 1270e5edfa8e00ec6306e0921c54d5c130a01b54 (diff) | |
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
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, |
