Files
FX-ML-Trading-Engine/QuantTrader/execution/order_store.py
T
2025-11-14 22:56:44 +00:00

29 lines
868 B
Python

"""Simple JSONL order store for audit/replay."""
from __future__ import annotations
import json
from dataclasses import asdict
from pathlib import Path
from typing import Iterable
from QuantTrader.execution.adapter import OrderParams
class OrderStore:
def __init__(self, path: str = "results/execution/orders.log"):
self.path = Path(path)
self.path.parent.mkdir(parents=True, exist_ok=True)
def append(self, order_id: str, params: OrderParams) -> None:
record = {"order_id": order_id, **asdict(params)}
with self.path.open("a", encoding="utf-8") as fh:
fh.write(json.dumps(record) + "\n")
def load(self) -> Iterable[dict]:
if not self.path.exists():
return []
with self.path.open("r", encoding="utf-8") as fh:
for line in fh:
yield json.loads(line)