fix: add DASH-003 live trades and session rows
This commit is contained in:
@@ -80,8 +80,12 @@ def newest_matching(log_dir: Path, pattern: str, regex: re.Pattern[str]) -> Opti
|
||||
|
||||
def today_trades_file(log_dir: Path) -> Optional[Path]:
|
||||
today = datetime.now().strftime("%Y%m%d")
|
||||
candidates = sorted(path for path in log_dir.rglob("trades_Simple_ORB_NT8_{0}.jsonl".format(today)) if path.is_file()) if log_dir.exists() else []
|
||||
return candidates[-1] if candidates else newest_matching(log_dir, "trades_Simple_ORB_NT8_*.jsonl", TRADES_FILE_RE)
|
||||
return trades_file_for_date(log_dir, today)
|
||||
|
||||
|
||||
def trades_file_for_date(log_dir: Path, yyyymmdd: str) -> Optional[Path]:
|
||||
candidates = sorted(path for path in log_dir.glob("trades_Simple_ORB_NT8_{0}.jsonl".format(yyyymmdd)) if path.is_file()) if log_dir.exists() else []
|
||||
return candidates[-1] if candidates else None
|
||||
|
||||
|
||||
def latest_provenance_file(log_dir: Path) -> Optional[Path]:
|
||||
@@ -260,16 +264,27 @@ def read_trades(path: Optional[Path]) -> List[Dict[str, Any]]:
|
||||
if path is None or not path.exists():
|
||||
return []
|
||||
records: List[Dict[str, Any]] = []
|
||||
date = None
|
||||
match = TRADES_FILE_RE.match(path.name)
|
||||
if match:
|
||||
raw = match.group(1)
|
||||
date = "{0}-{1}-{2}".format(raw[0:4], raw[4:6], raw[6:8])
|
||||
try:
|
||||
with path.open("r", encoding="utf-8", errors="replace") as handle:
|
||||
for line in handle:
|
||||
for line_number, line in enumerate(handle, start=1):
|
||||
text = line.strip()
|
||||
if not text:
|
||||
continue
|
||||
try:
|
||||
records.append(json.loads(text))
|
||||
record = json.loads(text)
|
||||
except ValueError:
|
||||
continue
|
||||
if isinstance(record, dict):
|
||||
if date is not None and "date" not in record:
|
||||
record["date"] = date
|
||||
record.setdefault("path", path.name)
|
||||
record.setdefault("line", line_number)
|
||||
records.append(record)
|
||||
except OSError:
|
||||
return []
|
||||
return records
|
||||
|
||||
Reference in New Issue
Block a user