Fix loading of new accounts without trades on live mt5 eas page

This commit is contained in:
unknown
2026-06-13 07:42:38 +10:00
parent 626ff6d91b
commit f60cc3790c
2 changed files with 18 additions and 11 deletions
+14 -7
View File
@@ -9,9 +9,13 @@ Parsers for three MT5 trade report formats:
All normalise to a common DataFrame schema.
"""
from curses import raw
import pandas as pd
import re
from streamlit import text
# ── Common schema ─────────────────────────────────────────────────────────────
# open_time, close_time, symbol, type, volume, open_price, close_price,
@@ -398,19 +402,22 @@ def detect_and_parse(file_bytes, filename=''):
Returns (df, format_name) or (None, None).
"""
fname = filename.lower()
# Derive a fallback strategy name from the filename for files where
# all comments are MT5 close-reason tags (sl/tp/so) and no strategy
# name is embedded in the comment field.
fallback = _strategy_from_filename(filename) if filename else None
if fname.endswith('.csv'):
df = parse_quant_csv(file_bytes, fallback_strategy=fallback)
return df, 'Quant Analyzer CSV'
# HTML/HTM — detect backtest vs real account
try:
text = _decode(file_bytes)
except:
# HTML/HTM — decode with UTF-16 support first
text = None
for enc in ['utf-16', 'utf-8', 'latin-1']:
try:
text = file_bytes.decode(enc)
break
except Exception:
continue
if text is None:
return None, None
if 'Strategy Tester Report' in text or 'strategy tester' in text.lower():
+4 -4
View File
@@ -116,13 +116,13 @@ def refresh_account(cfg: dict, account_folder: str, label: str = "") -> dict:
if raw is None:
return {"error": f"No report found for {account_folder}"}
df, fmt = detect_and_parse(raw, f"{account_folder}.htm")
if df is None or df.empty:
if df is None:
return {"error": f"Could not parse report for {account_folder}"}
stats = calc_stats(df)
# Also parse open positions if present
# df.empty is valid for a new account with no closed trades yet
stats = calc_stats(df) if not df.empty else {}
from mt5_parser import parse_open_positions
df_open = parse_open_positions(raw)
data = {
data = {
"account_folder": account_folder,
"label" : label or account_folder,
"df" : df,