fix: trade_budget_eur + preferred_horizon saved and reloaded in Config

Backend:
- CycleConfigRequest: add trade_budget_eur, preferred_horizon_min/max fields
  (were missing — Pydantic silently dropped them, so saves never reached set_config)
- update_cycle_config: handle + persist the 3 new fields via set_config
- get_status(): read + return trade_budget_eur/preferred_horizon_min/max from DB
  (were missing — frontend always fell back to React default values on page load)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-22 20:25:31 +02:00
parent 6cca7f66b6
commit 198341b0c2
2 changed files with 22 additions and 0 deletions

View File

@@ -44,6 +44,9 @@ class CycleConfigRequest(BaseModel):
similarity_threshold: Optional[float] = None
min_ev_threshold: Optional[float] = None
min_score_threshold: Optional[int] = None
trade_budget_eur: Optional[float] = None
preferred_horizon_min: Optional[int] = None
preferred_horizon_max: Optional[int] = None
journal_retention_days: Optional[int] = None
maturity_threshold_pct: Optional[int] = None
weekend_cycle_enabled: Optional[bool] = None
@@ -81,6 +84,18 @@ def update_cycle_config(req: CycleConfigRequest):
set_config("maturity_threshold_pct", str(req.maturity_threshold_pct))
if req.weekend_cycle_enabled is not None:
set_config("weekend_cycle_enabled", "true" if req.weekend_cycle_enabled else "false")
if req.trade_budget_eur is not None:
if not (100 <= req.trade_budget_eur <= 500_000):
raise HTTPException(400, "trade_budget_eur must be between 100 and 500000")
set_config("trade_budget_eur", str(req.trade_budget_eur))
if req.preferred_horizon_min is not None:
if not (1 <= req.preferred_horizon_min <= 365):
raise HTTPException(400, "preferred_horizon_min must be between 1 and 365")
set_config("preferred_horizon_min", str(req.preferred_horizon_min))
if req.preferred_horizon_max is not None:
if not (1 <= req.preferred_horizon_max <= 365):
raise HTTPException(400, "preferred_horizon_max must be between 1 and 365")
set_config("preferred_horizon_max", str(req.preferred_horizon_max))
if req.weekend_cycle_times is not None:
# Validate format: comma-separated HH:MM values
import re

View File

@@ -1956,9 +1956,13 @@ def get_status() -> Dict[str, Any]:
min_score = int(get_config("min_score_threshold") or "0")
retention_days = int(get_config("journal_retention_days") or "90")
maturity_pct = int(get_config("maturity_threshold_pct") or "35")
trade_budget_eur = float(get_config("trade_budget_eur") or "5000")
preferred_horizon_min = int(get_config("preferred_horizon_min") or "30")
preferred_horizon_max = int(get_config("preferred_horizon_max") or "180")
except Exception:
interval_hours, enabled, sim_threshold, min_ev, min_score = 3.0, False, 0.30, 0.0, 0
retention_days, maturity_pct = 90, 35
trade_budget_eur, preferred_horizon_min, preferred_horizon_max = 5000.0, 30, 180
recent = get_cycle_runs(limit=1)
last = recent[0] if recent else None
@@ -1997,6 +2001,9 @@ def get_status() -> Dict[str, Any]:
"min_score_threshold": min_score,
"journal_retention_days": retention_days,
"maturity_threshold_pct": maturity_pct,
"trade_budget_eur": trade_budget_eur,
"preferred_horizon_min": preferred_horizon_min,
"preferred_horizon_max": preferred_horizon_max,
"weekend_cycle_enabled": weekend_enabled,
"weekend_cycle_times": weekend_cycle_times,
"last_cycle": last,