mirror of
https://github.com/xavierchuan/FX-ML-Trading-Engine.git
synced 2026-07-28 02:27:43 +00:00
29 lines
868 B
Python
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)
|