mirror of
https://github.com/xavierchuan/FX-ML-Trading-Engine.git
synced 2026-08-15 09:58:06 +00:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user