Coverage for scripts/lean_smoke/make_field_test_config.py: 100%
44 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1"""The configs of the field test (V6.6.5, #351): Lean's launcher config for main.py under `live-paper` with a FakeDataQueue
2(the live-plumbing one), and a project config that trades two coins at minute resolution in paper mode with the field-test
3plan on. Both are written outside the repo; lean.json and config.json are read, never changed.
5 python scripts/lean_smoke/make_field_test_config.py --lean-json lean.json --out launcher.json --project-config <project>/config.json
6"""
8from __future__ import annotations
10import argparse
11import copy
12import json
13import sys
14from pathlib import Path
16sys.path.insert(0, str(Path(__file__).resolve().parent))
18from make_live_plumbing_config import launcher_config
20COINS = ("BTCUSD", "ETHUSD")
21PLAN = {
22 "enabled": True,
23 "order_after_bars": 3,
24 "target_weights": {"BTCUSD": 0.30, "ETHUSD": 0.20},
25 "drift_after_bars": 8,
26 "drift_symbol": "BTCUSD",
27 "drift_weight": 0.20,
28 "shock_after_bars": 14,
29 "drawdown_shock_pct": 0.05,
30}
33def project_config(config: dict, coins: tuple[str, ...] = COINS) -> dict:
34 """Two coins (crypto trades on a Sunday), one-minute bars, paper mode on Lean's paper brokerage, the plan on."""
35 config = copy.deepcopy(config)
36 universe = config["phase1"]["universe"]
37 universe["assets"] = [asset for asset in universe["assets"] if asset["ticker"] in coins]
38 universe["resolution"] = "Minute"
39 config.setdefault("runtime", {})["warmup_bars"] = 1
40 phase_v2 = config["phase_v2"]
41 # paper orders need allow_live_orders; they go to Lean's simulated PaperBrokerage, never a venue
42 phase_v2["runtime"] = {"mode": "paper", "allow_live_orders": True}
43 paper = phase_v2.setdefault("paper_trading", {})
44 paper.update({"brokerage": "lean_paper_brokerage", "live_data_provider_configured": True, "manual_review_confirmed": True})
45 target = phase_v2.setdefault("target_weights", {})
46 target["enabled"] = True
47 target["live_reload"] = False
48 target["min_trade_usd"] = 1.0
49 kill = phase_v2.setdefault("risk", {}).setdefault("kill_switch", {})
50 kill.update({"enabled": True, "max_drawdown_velocity_pct_per_bar": 0.02, "trip_confirm_bars": 1, "action": "trade_lock"})
51 reconciliation = phase_v2.setdefault("reconciliation", {})
52 reconciliation.update({"enabled": True, "trips_kill_switch": False, "max_tolerated_drift": 0.05})
53 phase_v2.setdefault("diagnostics", {})["field_test"] = dict(PLAN)
54 return config
57def main() -> int:
58 parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
59 parser.add_argument("--lean-json", default="lean.json")
60 parser.add_argument("--out", required=True)
61 parser.add_argument("--project-config", required=True, help="the copy of config.json inside the temp project; rewritten in place")
62 args = parser.parse_args()
63 lean = json.loads(Path(args.lean_json).read_text(encoding="utf-8"))
64 Path(args.out).write_text(json.dumps(launcher_config(lean), indent=1), encoding="utf-8", newline="\n")
65 project = Path(args.project_config)
66 project.write_text(json.dumps(project_config(json.loads(project.read_text(encoding="utf-8"))), indent=1), encoding="utf-8", newline="\n")
67 print(f"wrote {args.out} and the field-test project config {args.project_config}")
68 return 0
71if __name__ == "__main__":
72 raise SystemExit(main())