diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 17:46:47 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2026-04-01 17:46:47 +0900 |
| commit | 69e88b3b353f1a2ab7a78259b480e8afbd87669c (patch) | |
| tree | 712de7c4dd0bd16ba853a77d012ebed7c57d91c7 /services/api/src/trading_api/routers/strategies.py | |
| parent | 678005dc51892c4c1f4cea2730bbf0ec4ebc312d (diff) | |
fix: snapshot delay, env fields, alembic creds, API healthcheck and error handling
Diffstat (limited to 'services/api/src/trading_api/routers/strategies.py')
| -rw-r--r-- | services/api/src/trading_api/routers/strategies.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/services/api/src/trading_api/routers/strategies.py b/services/api/src/trading_api/routers/strategies.py index 2861eec..e968529 100644 --- a/services/api/src/trading_api/routers/strategies.py +++ b/services/api/src/trading_api/routers/strategies.py @@ -1,30 +1,37 @@ """Strategy endpoints.""" +import logging import sys from pathlib import Path -from fastapi import APIRouter +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)) +logger = logging.getLogger(__name__) + router = APIRouter() @router.get("/") async def list_strategies(): """List available strategies.""" - from strategy_engine.plugin_loader import load_strategies - - strategies_dir = _STRATEGY_DIR / "strategies" - strategies = load_strategies(strategies_dir) - return [ - { - "name": s.name, - "warmup_period": s.warmup_period, - "class": type(s).__name__, - } - for s in strategies - ] + try: + from strategy_engine.plugin_loader import load_strategies + + strategies_dir = _STRATEGY_DIR / "strategies" + strategies = load_strategies(strategies_dir) + return [ + { + "name": s.name, + "warmup_period": s.warmup_period, + "class": type(s).__name__, + } + for s in strategies + ] + except Exception as exc: + logger.error("Failed to list strategies: %s", exc) + raise HTTPException(status_code=500, detail="Failed to list strategies") |
