Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions python/valuecell/server/api/routers/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,44 @@ 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

Expand All @@ -119,7 +152,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)),
Expand Down