Initial strategy32 research and live runtime
This commit is contained in:
62
scripts/run_live_monitor.py
Normal file
62
scripts/run_live_monitor.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
PACKAGE_PARENT = Path(__file__).resolve().parents[2]
|
||||
if str(PACKAGE_PARENT) not in sys.path:
|
||||
sys.path.insert(0, str(PACKAGE_PARENT))
|
||||
|
||||
from strategy32.live.env import load_dotenv
|
||||
from strategy32.live.runtime import run_monitor
|
||||
|
||||
|
||||
def _default_env_candidates() -> list[Path]:
|
||||
return [
|
||||
Path(__file__).resolve().parents[1] / ".env",
|
||||
Path("/Volumes/SSD/workspace/money-bot/strategy11/.env"),
|
||||
Path("/Volumes/SSD/workspace/money-bot/strategy7/engine_a_mm/.env"),
|
||||
Path("/Volumes/SSD/workspace/money-bot/strategy7/engine_aa_mm/.env"),
|
||||
]
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="Run Strategy32 live paper/advisory monitor")
|
||||
parser.add_argument("--once", action="store_true", help="Run one cycle and exit")
|
||||
parser.add_argument("--runtime-dir", type=str, default=os.getenv("STRATEGY32_RUNTIME_DIR", "runtime"))
|
||||
parser.add_argument("--env-file", type=str, default="")
|
||||
parser.add_argument("--log-level", type=str, default=os.getenv("STRATEGY32_LOG_LEVEL", "INFO"))
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = parse_args()
|
||||
if args.env_file:
|
||||
load_dotenv(args.env_file)
|
||||
else:
|
||||
for env_path in _default_env_candidates():
|
||||
if env_path.exists():
|
||||
load_dotenv(env_path)
|
||||
break
|
||||
|
||||
runtime_dir = Path(args.runtime_dir)
|
||||
runtime_dir.mkdir(parents=True, exist_ok=True)
|
||||
handlers: list[logging.Handler] = [
|
||||
logging.StreamHandler(),
|
||||
logging.FileHandler(runtime_dir / "strategy32_live.log", encoding="utf-8"),
|
||||
]
|
||||
logging.basicConfig(
|
||||
level=getattr(logging, args.log_level.upper(), logging.INFO),
|
||||
format="%(asctime)s %(levelname)-5s %(name)s %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
handlers=handlers,
|
||||
)
|
||||
asyncio.run(run_monitor(once=args.once, runtime_dir=args.runtime_dir))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user