|
@@ -310,8 +310,8 @@ def switch_strategy(*, account_id: str, market_symbol: str | None, target_strate
|
|
|
return {"ok": False, "status": "rejected", "error": "expected active strategy mismatch", "from_strategy_id": current_id}
|
|
return {"ok": False, "status": "rejected", "error": "expected active strategy mismatch", "from_strategy_id": current_id}
|
|
|
if current_id == target_strategy_id:
|
|
if current_id == target_strategy_id:
|
|
|
return {"ok": True, "status": "noop", "from_strategy_id": current_id, "to_strategy_id": target_strategy_id, "reconciled": False}
|
|
return {"ok": True, "status": "noop", "from_strategy_id": current_id, "to_strategy_id": target_strategy_id, "reconciled": False}
|
|
|
- if current_id and _is_degraded(current_id) and not override:
|
|
|
|
|
- return {"ok": False, "status": "rejected", "error": "current strategy is execution-degraded", "from_strategy_id": current_id}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ degraded_current = bool(current_id and _is_degraded(current_id))
|
|
|
|
|
|
|
|
if current_id:
|
|
if current_id:
|
|
|
update_strategy_mode(current_id, "off")
|
|
update_strategy_mode(current_id, "off")
|
|
@@ -321,7 +321,11 @@ def switch_strategy(*, account_id: str, market_symbol: str | None, target_strate
|
|
|
if not ok:
|
|
if not ok:
|
|
|
return {"ok": False, "status": "failed", "error": "failed to activate target strategy", "from_strategy_id": current_id, "to_strategy_id": target_strategy_id}
|
|
return {"ok": False, "status": "failed", "error": "failed to activate target strategy", "from_strategy_id": current_id, "to_strategy_id": target_strategy_id}
|
|
|
reconcile_instance(target_strategy_id)
|
|
reconcile_instance(target_strategy_id)
|
|
|
- return {"ok": True, "status": "applied", "from_strategy_id": current_id, "to_strategy_id": target_strategy_id, "reconciled": True}
|
|
|
|
|
|
|
+ result = {"ok": True, "status": "applied", "from_strategy_id": current_id, "to_strategy_id": target_strategy_id, "reconciled": True}
|
|
|
|
|
+ if degraded_current:
|
|
|
|
|
+ result["warning"] = "previous active strategy was execution-degraded"
|
|
|
|
|
+ result["current_degraded"] = True
|
|
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_control_decision(payload: dict) -> dict:
|
|
def apply_control_decision(payload: dict) -> dict:
|
|
@@ -357,6 +361,7 @@ def apply_control_decision(payload: dict) -> dict:
|
|
|
"target_exists": None,
|
|
"target_exists": None,
|
|
|
"target_scope_match": None,
|
|
"target_scope_match": None,
|
|
|
"expected_active_match": None,
|
|
"expected_active_match": None,
|
|
|
|
|
+ "current_degraded": None,
|
|
|
}
|
|
}
|
|
|
errors: list[str] = []
|
|
errors: list[str] = []
|
|
|
|
|
|
|
@@ -396,6 +401,7 @@ def apply_control_decision(payload: dict) -> dict:
|
|
|
current = _active_strategy_for_scope(account_id, market_symbol)
|
|
current = _active_strategy_for_scope(account_id, market_symbol)
|
|
|
current_id = getattr(current, "id", None)
|
|
current_id = getattr(current, "id", None)
|
|
|
validation["expected_active_match"] = (current_id == expected_active_strategy_id) if expected_active_strategy_id else None
|
|
validation["expected_active_match"] = (current_id == expected_active_strategy_id) if expected_active_strategy_id else None
|
|
|
|
|
+ validation["current_degraded"] = bool(current_id and _is_degraded(current_id))
|
|
|
if expected_active_strategy_id and current_id != expected_active_strategy_id and not override:
|
|
if expected_active_strategy_id and current_id != expected_active_strategy_id and not override:
|
|
|
errors.append("expected active strategy mismatch")
|
|
errors.append("expected active strategy mismatch")
|
|
|
|
|
|