fix: repair DASH-001 live session state and readiness panel

This commit is contained in:
2026-08-17 10:47:53 -04:00
parent 8ca000a166
commit e7b6ae5878
7 changed files with 251 additions and 15 deletions

View File

@@ -21,7 +21,14 @@ FILL_RE = re.compile(r"\bFILL\b\s+(Long|Short)\s+(\d+)\s+@\s+([0-9.]+)", re.IGNO
BREAKEVEN_RE = re.compile(r"\bBREAKEVEN\b\s*(.*)$", re.IGNORECASE)
RUNNER_CLOSED_RE = re.compile(r"RUNNER closed", re.IGNORECASE)
CONNECTION_RE = re.compile(r"CONNECTION\s+(LOST|RESTORED)", re.IGNORECASE)
CONNECTION_STATE_RE = re.compile(r"^ConnectionLost\s*:\s*(True|False)$", re.IGNORECASE)
PNL_RE = re.compile(r"PNL_UPDATE\s+DayPnL=([^\s]+)\s+Position=([^\s]+)\s+Qty=(\d+)", re.IGNORECASE)
ACCOUNT_RE = re.compile(r"^Account\s*:\s*(.+)$", re.IGNORECASE)
SYMBOL_RE = re.compile(r"^Symbol\s*:\s*(.+)$", re.IGNORECASE)
MODE_RE = re.compile(r"^Mode\s*:\s*(.+)$", re.IGNORECASE)
DATA_SERIES_RE = re.compile(r"DataSeries\[(\d+)\]\s*:\s*Type=([^\s]+)\s+DaysToLoad=([^\s]+)\s+HistoricalBarsLoaded=([^\s]+)", re.IGNORECASE)
FACTOR_WARMUP_RE = re.compile(r"FactorWarmup\s*:\s*(.*)$", re.IGNORECASE)
FACTOR_STATUS_RE = re.compile(r"([A-Za-z0-9_]+)=(SATISFIED|FAILED|UNSATISFIED)\s*\((\d+)/(\d+)\s+daily bars\)", re.IGNORECASE)
def expand_path(raw_path: str) -> Path:
@@ -29,17 +36,29 @@ def expand_path(raw_path: str) -> Path:
def newest_session_file(log_dir: Path) -> Optional[Path]:
newest: Optional[Tuple[datetime, Path]] = None
for path in log_dir.rglob("session_*.log") if log_dir.exists() else []:
newest: Optional[Tuple[float, str, Path]] = None
for path in log_dir.glob("session_*.log") if log_dir.exists() else []:
if not path.is_file():
continue
match = SESSION_FILE_RE.match(path.name)
if match is None:
continue
stamp = datetime.strptime("{0}_{1}".format(match.group(1), match.group(2)), "%Y%m%d_%H%M%S")
if newest is None or stamp > newest[0]:
newest = (stamp, path)
return newest[1] if newest else None
try:
mtime = path.stat().st_mtime
except OSError:
continue
if newest is None or (mtime, path.name) > (newest[0], newest[1]):
newest = (mtime, path.name, path)
return newest[2] if newest else None
def session_key(path: Path, lines: List[str]) -> str:
for line in lines:
timestamp, message = split_log_line(line)
start = SESSION_START_RE.search(message)
if start:
return start.group(1)
return path.stem
def newest_matching(log_dir: Path, pattern: str, regex: re.Pattern[str]) -> Optional[Path]:
@@ -129,15 +148,77 @@ def parse_session_event(path: Path, line: str) -> Optional[Dict[str, Any]]:
payload.update({"type": "CONNECTION {0}".format(connection.group(1).upper()), "status": connection.group(1).upper()})
return payload
connection_state = CONNECTION_STATE_RE.search(message)
if connection_state:
payload = dict(base)
payload.update({"type": "CONNECTION STATE", "status": "LOST" if connection_state.group(1).lower() == "true" else "OK"})
return payload
pnl = PNL_RE.search(message)
if pnl:
payload = dict(base)
payload.update({"type": "PNL_UPDATE", "daily_pnl": parse_money(pnl.group(1)), "position": pnl.group(2), "quantity": int(pnl.group(3))})
return payload
account = ACCOUNT_RE.search(message)
if account:
payload = dict(base)
payload.update({"type": "ACCOUNT", "account": account.group(1).strip()})
return payload
symbol = SYMBOL_RE.search(message)
if symbol:
payload = dict(base)
payload.update({"type": "SYMBOL", "symbol": symbol.group(1).strip()})
return payload
mode = MODE_RE.search(message)
if mode:
payload = dict(base)
payload.update({"type": "MODE", "mode": mode.group(1).strip()})
return payload
return None
def parse_readiness(lines: List[str]) -> Dict[str, Any]:
data_series: Dict[int, Dict[str, Any]] = {}
factors: Dict[str, Dict[str, Any]] = {}
context = ""
bars_required = ""
for line in lines:
timestamp, message = split_log_line(line)
if message.startswith("Historical readiness"):
context = message
required = re.search(r"BarsRequiredToTrade=([^\s]+)", message, re.IGNORECASE)
if required:
bars_required = required.group(1)
data_match = DATA_SERIES_RE.search(message)
if data_match:
index = int(data_match.group(1))
data_series[index] = {
"index": index,
"type": data_match.group(2),
"days_to_load": data_match.group(3),
"historical_bars_loaded": data_match.group(4),
}
warmup = FACTOR_WARMUP_RE.search(message)
if warmup:
for factor in FACTOR_STATUS_RE.finditer(warmup.group(1)):
factors[factor.group(1)] = {
"name": factor.group(1),
"status": factor.group(2).upper(),
"loaded": int(factor.group(3)),
"required": int(factor.group(4)),
}
return {
"context": context,
"bars_required_to_trade": bars_required,
"data_series": [data_series[index] for index in sorted(data_series.keys())],
"factors": [factors[name] for name in sorted(factors.keys())],
}
def read_new_complete_lines(path: Path, offset: int, partial: str) -> Tuple[List[str], int, str]:
try:
size = path.stat().st_size