feat: Add runtime config validation for cash, margin and memory settings
- Add initial_cash validation (must be positive number) - Add margin_requirement validation (must be non-negative) - Add enable_memory boolean configuration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1236,6 +1236,48 @@ class Gateway:
|
|||||||
return
|
return
|
||||||
updates["max_comm_cycles"] = parsed_cycles
|
updates["max_comm_cycles"] = parsed_cycles
|
||||||
|
|
||||||
|
initial_cash = data.get("initial_cash")
|
||||||
|
if initial_cash is not None:
|
||||||
|
try:
|
||||||
|
parsed_initial_cash = float(initial_cash)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
parsed_initial_cash = 0.0
|
||||||
|
if parsed_initial_cash <= 0:
|
||||||
|
await websocket.send(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"type": "error",
|
||||||
|
"message": "initial_cash must be a positive number.",
|
||||||
|
},
|
||||||
|
ensure_ascii=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
updates["initial_cash"] = parsed_initial_cash
|
||||||
|
|
||||||
|
margin_requirement = data.get("margin_requirement")
|
||||||
|
if margin_requirement is not None:
|
||||||
|
try:
|
||||||
|
parsed_margin_requirement = float(margin_requirement)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
parsed_margin_requirement = -1.0
|
||||||
|
if parsed_margin_requirement < 0:
|
||||||
|
await websocket.send(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"type": "error",
|
||||||
|
"message": "margin_requirement must be a non-negative number.",
|
||||||
|
},
|
||||||
|
ensure_ascii=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
updates["margin_requirement"] = parsed_margin_requirement
|
||||||
|
|
||||||
|
enable_memory = data.get("enable_memory")
|
||||||
|
if enable_memory is not None:
|
||||||
|
updates["enable_memory"] = bool(enable_memory)
|
||||||
|
|
||||||
if not updates:
|
if not updates:
|
||||||
await websocket.send(
|
await websocket.send(
|
||||||
json.dumps(
|
json.dumps(
|
||||||
|
|||||||
Reference in New Issue
Block a user