64 lines
2.5 KiB
Python
64 lines
2.5 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 CouncilGovernanceTickService
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
instrument_id = int(env.get("RESEARCH_COUNCIL_INSTRUMENT_ID", "1"))
|
|
limit = int(env.get("RESEARCH_COUNCIL_REVIEW_LIMIT", "5"))
|
|
stale_after_hours = float(env.get("RESEARCH_COUNCIL_STALE_AFTER_HOURS", "24"))
|
|
auto_run_stale_cycle = _get_bool(env, "RESEARCH_COUNCIL_GOVERNANCE_AUTO_RUN_STALE", False)
|
|
force_cycle = _get_bool(env, "RESEARCH_COUNCIL_GOVERNANCE_FORCE_CYCLE", False)
|
|
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
|
|
output_json = _get_bool(env, "RESEARCH_COUNCIL_OUTPUT_JSON", False)
|
|
payload = CouncilGovernanceTickService().run_tick(
|
|
instrument_id=instrument_id,
|
|
limit=limit,
|
|
stale_after_hours=stale_after_hours,
|
|
auto_run_stale_cycle=auto_run_stale_cycle,
|
|
force_cycle=force_cycle,
|
|
timeframe=timeframe,
|
|
model_code=model_code,
|
|
replay_file=replay_file,
|
|
eval_limit=eval_limit,
|
|
lesson_limit=lesson_limit,
|
|
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 governance tick {payload.get('status')} for instrument {payload.get('instrument_id')}")
|
|
print(f"Health: {payload.get('effective_health_state')}")
|
|
print(f"Actions: {', '.join(payload.get('recommended_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())
|