Coverage for scripts/lean_smoke/make_live_plumbing_config.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""The two configs for `live_plumbing.sh` (V6.6.4, B6): Lean's launcher config for main.py under `live-paper` with a FakeDataQueue, and a project config trimmed to a few 

2crypto names so the algorithm starts quickly. Both are written outside the repo; lean.json and config.json are read, never changed. 

3 

4 python scripts/lean_smoke/make_live_plumbing_config.py --lean-json lean.json --out launcher.json --project-config <project>/config.json 

5""" 

6 

7from __future__ import annotations 

8 

9import argparse 

10import copy 

11import json 

12from pathlib import Path 

13 

14FAKE_QUEUE = "QuantConnect.Lean.Engine.DataFeeds.Queues.FakeDataQueue" 

15 

16 

17def launcher_config(lean: dict) -> dict: 

18 base = {key: copy.deepcopy(value) for key, value in lean.items() if key != "environments"} 

19 environments = lean["environments"] 

20 live = copy.deepcopy(environments["live-paper"]) 

21 live["data-queue-handler"] = [FAKE_QUEUE] 

22 base.update(live) 

23 base.update({ 

24 "environment": "live-paper-fake", 

25 "algorithm-type-name": "AetherQuantAlgorithm", 

26 "algorithm-language": "Python", 

27 "algorithm-location": "/LeanCLI/main.py", 

28 "data-folder": "/Lean/Data", 

29 "results-destination-folder": "/Results", 

30 "debugging": False, 

31 "live-mode": True, 

32 "python-additional-paths": ["/LeanCLI"], 

33 "parameters": {}, 

34 }) 

35 base["environments"] = {"live-paper-fake": live} 

36 return base 

37 

38 

39def project_config(config: dict, keep: tuple[str, ...] = ("BTCUSD", "ETHUSD", "SOLUSD", "SPY", "TLT")) -> dict: 

40 config = copy.deepcopy(config) 

41 assets = [asset for asset in config["phase1"]["universe"]["assets"] if asset["ticker"] in keep] 

42 config["phase1"]["universe"]["assets"] = assets 

43 runtime = config.setdefault("runtime", {}) 

44 runtime["mode"] = "paper" 

45 return config 

46 

47 

48def main() -> int: 

49 parser = argparse.ArgumentParser(description=__doc__) 

50 parser.add_argument("--lean-json", default="lean.json") 

51 parser.add_argument("--out", required=True) 

52 parser.add_argument("--project-config", required=True, help="the copy of config.json inside the temp project; rewritten in place") 

53 args = parser.parse_args() 

54 lean = json.loads(Path(args.lean_json).read_text(encoding="utf-8")) 

55 Path(args.out).write_text(json.dumps(launcher_config(lean), indent=1), encoding="utf-8", newline="\n") 

56 project = Path(args.project_config) 

57 project.write_text(json.dumps(project_config(json.loads(project.read_text(encoding="utf-8"))), indent=1), encoding="utf-8", newline="\n") 

58 print(f"wrote {args.out} and trimmed {args.project_config}") 

59 return 0 

60 

61 

62if __name__ == "__main__": 

63 raise SystemExit(main())