Add broker reconciliation trade loop
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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.reconciliation import BrokerExecutionReconciliationService
|
||||
|
||||
|
||||
def main(env=None) -> int:
|
||||
env = os.environ if env is None else env
|
||||
instrument_id = int(env.get("BROKER_RECONCILIATION_INSTRUMENT_ID", "1"))
|
||||
output_json = _get_bool(env, "BROKER_RECONCILIATION_OUTPUT_JSON", False)
|
||||
summary = BrokerExecutionReconciliationService().reconcile_instrument(instrument_id=instrument_id)
|
||||
if output_json:
|
||||
print(json.dumps(summary, ensure_ascii=False, sort_keys=True))
|
||||
else:
|
||||
print(f"Reconciliation status: {summary.get('status')}")
|
||||
print(f"Matched executions: {summary.get('matched_execution_ids') or []}")
|
||||
print(f"Imported executions: {summary.get('imported_execution_ids') or []}")
|
||||
return 0 if summary.get("status") == "ok" else 2
|
||||
|
||||
|
||||
def _get_bool(env, key: str, default: bool = False) -> 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())
|
||||
Reference in New Issue
Block a user