From 8b25fb4597485e4df6945dd87d667377d25a5a8b Mon Sep 17 00:00:00 2001 From: paisley Date: Thu, 20 Nov 2025 18:30:06 +0800 Subject: [PATCH 1/2] update --- .../valuecell/server/api/routers/strategy.py | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/python/valuecell/server/api/routers/strategy.py b/python/valuecell/server/api/routers/strategy.py index 812c23062..e0512ccf7 100644 --- a/python/valuecell/server/api/routers/strategy.py +++ b/python/valuecell/server/api/routers/strategy.py @@ -104,11 +104,34 @@ def to_optional_float(value) -> Optional[float]: except Exception: return None - def normalize_strategy_type(meta: dict) -> Optional[StrategyType]: - raw = (meta.get("strategy_type") or "").strip().lower() - if raw == "prompt based strategy": + def normalize_strategy_type(meta: dict, cfg: dict) -> Optional[StrategyType]: + val = meta.get("strategy_type") + if not val: + val = (cfg.get("trading_config", {}) or {}).get("strategy_type") + if val is None: + agent_name = str(meta.get("agent_name") or "").lower() + if "prompt" in agent_name: + return StrategyType.PROMPT + if "grid" in agent_name: + return StrategyType.GRID + return None + + raw = str(val).strip().lower() + if raw.startswith("strategytype."): + raw = raw.split(".", 1)[1] + raw_compact = "".join(ch for ch in raw if ch.isalnum()) + + if raw in ("prompt based strategy", "grid strategy"): + return StrategyType.PROMPT if raw.startswith("prompt") else StrategyType.GRID + if raw_compact in ("promptbasedstrategy", "gridstrategy"): + return StrategyType.PROMPT if raw_compact.startswith("prompt") else StrategyType.GRID + if raw in ("prompt", "grid"): + return StrategyType.PROMPT if raw == "prompt" else StrategyType.GRID + + agent_name = str(meta.get("agent_name") or "").lower() + if "prompt" in agent_name: return StrategyType.PROMPT - if raw == "grid strategy": + if "grid" in agent_name: return StrategyType.GRID return None @@ -119,7 +142,7 @@ def normalize_strategy_type(meta: dict) -> Optional[StrategyType]: item = StrategySummaryData( strategy_id=s.strategy_id, strategy_name=s.name, - strategy_type=normalize_strategy_type(meta), + strategy_type=normalize_strategy_type(meta, cfg), status=map_status(s.status), trading_mode=normalize_trading_mode(meta, cfg), unrealized_pnl=to_optional_float(meta.get("unrealized_pnl", 0.0)), From 683656a89f2eb43f74310a287311d47c4b59c314 Mon Sep 17 00:00:00 2001 From: paisley Date: Thu, 20 Nov 2025 18:46:26 +0800 Subject: [PATCH 2/2] lint --- python/valuecell/server/api/routers/strategy.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/python/valuecell/server/api/routers/strategy.py b/python/valuecell/server/api/routers/strategy.py index e0512ccf7..d296d0100 100644 --- a/python/valuecell/server/api/routers/strategy.py +++ b/python/valuecell/server/api/routers/strategy.py @@ -104,7 +104,9 @@ def to_optional_float(value) -> Optional[float]: except Exception: return None - def normalize_strategy_type(meta: dict, cfg: dict) -> Optional[StrategyType]: + def normalize_strategy_type( + meta: dict, cfg: dict + ) -> Optional[StrategyType]: val = meta.get("strategy_type") if not val: val = (cfg.get("trading_config", {}) or {}).get("strategy_type") @@ -122,9 +124,17 @@ def normalize_strategy_type(meta: dict, cfg: dict) -> Optional[StrategyType]: raw_compact = "".join(ch for ch in raw if ch.isalnum()) if raw in ("prompt based strategy", "grid strategy"): - return StrategyType.PROMPT if raw.startswith("prompt") else StrategyType.GRID + return ( + StrategyType.PROMPT + if raw.startswith("prompt") + else StrategyType.GRID + ) if raw_compact in ("promptbasedstrategy", "gridstrategy"): - return StrategyType.PROMPT if raw_compact.startswith("prompt") else StrategyType.GRID + return ( + StrategyType.PROMPT + if raw_compact.startswith("prompt") + else StrategyType.GRID + ) if raw in ("prompt", "grid"): return StrategyType.PROMPT if raw == "prompt" else StrategyType.GRID