Expose sim/live matching mode in env config UI.
Saving SIM_DEFAULT_MODE also switches runtime trading.mode immediately. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -51,12 +51,26 @@ def apply_env_reload(env_path: str, get_db: Callable, changed_keys: list[str], g
|
||||
field_map[field["key"]] = field
|
||||
for key in changed_keys:
|
||||
meta = field_map.get(key) or {}
|
||||
if meta.get("hot_reload") and not meta.get("restart_required"):
|
||||
# SIM_DEFAULT_MODE 不在 example schema 的 hot 列表时仍应热切
|
||||
is_hot = bool(meta.get("hot_reload") and not meta.get("restart_required"))
|
||||
if key == "SIM_DEFAULT_MODE":
|
||||
is_hot = True
|
||||
if is_hot:
|
||||
val = os.getenv(key)
|
||||
if val is not None:
|
||||
hot[key] = val
|
||||
if hot:
|
||||
set_config_overrides(get_db, hot)
|
||||
# 撮合模式:写入 .env 的同时切换运行时 trading.mode(sim|live)
|
||||
if "SIM_DEFAULT_MODE" in changed_keys:
|
||||
try:
|
||||
from lib.sim.mode_lib import set_trading_mode
|
||||
|
||||
raw = (os.getenv("SIM_DEFAULT_MODE") or "").strip().lower()
|
||||
if raw in ("sim", "live"):
|
||||
set_trading_mode(get_db, raw)
|
||||
except Exception:
|
||||
pass
|
||||
from lib.env.env_schema import updates_need_restart
|
||||
|
||||
return {"restart_required": updates_need_restart(groups, changed_keys)}
|
||||
|
||||
Reference in New Issue
Block a user