63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.services.research_council import CouncilOptimizationService
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
instrument_id = int(env.get("RESEARCH_COUNCIL_INSTRUMENT_ID", "1"))
|
|
timeframe = env.get("RESEARCH_COUNCIL_TIMEFRAME", "1m")
|
|
model_code = env.get("RESEARCH_COUNCIL_MODEL_CODE", "OSOK_DAILY_RANGE_SWEEP_MSS_FVG_RETRACE")
|
|
replay_file = str(env.get("RESEARCH_COUNCIL_REPLAY_FILE") or "").strip() or None
|
|
eval_limit = int(env.get("RESEARCH_COUNCIL_EVAL_LIMIT", "20"))
|
|
lesson_limit = int(env.get("RESEARCH_COUNCIL_LESSON_LIMIT", "100"))
|
|
cycle_key = str(env.get("RESEARCH_COUNCIL_OPTIMIZATION_CYCLE_KEY") or "").strip() or None
|
|
arena_model_codes = [
|
|
item.strip()
|
|
for item in str(env.get("RESEARCH_COUNCIL_ARENA_MODEL_CODES") or "").split(",")
|
|
if item.strip()
|
|
]
|
|
output_json = _get_bool(env, "RESEARCH_COUNCIL_OUTPUT_JSON", False)
|
|
|
|
payload = CouncilOptimizationService().run_cycle(
|
|
instrument_id=instrument_id,
|
|
timeframe=timeframe,
|
|
model_code=model_code,
|
|
replay_file=replay_file,
|
|
eval_limit=eval_limit,
|
|
lesson_limit=lesson_limit,
|
|
arena_model_codes=arena_model_codes or None,
|
|
cycle_key=cycle_key,
|
|
)
|
|
_print_payload(payload, output_json=output_json)
|
|
return 0 if payload.get("passed") else 2
|
|
|
|
|
|
def _print_payload(payload: dict, *, output_json: bool) -> None:
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
return
|
|
print(f"Research council optimization cycle {payload.get('status')} for instrument {payload.get('instrument_id')}")
|
|
print(f"Cycle: {payload.get('cycle_key')}")
|
|
print(f"Next actions: {', '.join(payload.get('next_actions') or [])}")
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|