fix: open positions table now matches MT5 HTML report columns
mt5_parser.py: - parse_open_positions: added market_price, swap, profit, comment columns to match all 11 columns in MT5 HTML Open Positions table view_live_mt5_eas.py: - Open positions table columns updated to match MT5 report order: Account, Time, Position, Symbol, Type, Volume, Price, S/L, T/P, Market Price, Swap, Profit, Comment
This commit is contained in:
+13
-9
@@ -365,15 +365,19 @@ def parse_open_positions(file_bytes) -> 'pd.DataFrame | None':
|
|||||||
try:
|
try:
|
||||||
vol_str = cells[4].split('/')[0].strip()
|
vol_str = cells[4].split('/')[0].strip()
|
||||||
positions.append({
|
positions.append({
|
||||||
'open_time' : _to_dt(cells[0]),
|
'open_time' : _to_dt(cells[0]),
|
||||||
'position' : cells[1],
|
'position' : cells[1],
|
||||||
'symbol' : cells[2],
|
'symbol' : cells[2],
|
||||||
'type' : cells[3].lower(),
|
'type' : cells[3].lower(),
|
||||||
'volume' : _to_float(vol_str),
|
'volume' : _to_float(vol_str),
|
||||||
'open_price' : _to_float(cells[5]),
|
'open_price' : _to_float(cells[5]),
|
||||||
'sl' : _to_float(cells[6]) if len(cells) > 6 else None,
|
'sl' : _to_float(cells[6]) if len(cells) > 6 else None,
|
||||||
'tp' : _to_float(cells[7]) if len(cells) > 7 else None,
|
'tp' : _to_float(cells[7]) if len(cells) > 7 else None,
|
||||||
'status' : 'open',
|
'market_price' : _to_float(cells[8]) if len(cells) > 8 else None,
|
||||||
|
'swap' : _to_float(cells[9]) if len(cells) > 9 else None,
|
||||||
|
'profit' : _to_float(cells[10]) if len(cells) > 10 else None,
|
||||||
|
'comment' : cells[11] if len(cells) > 11 else '',
|
||||||
|
'status' : 'open',
|
||||||
})
|
})
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
+20
-24
@@ -683,35 +683,31 @@ cache/
|
|||||||
|
|
||||||
if _all_open:
|
if _all_open:
|
||||||
open_df = pd.concat(_all_open, ignore_index=True)
|
open_df = pd.concat(_all_open, ignore_index=True)
|
||||||
|
col_order = ["_account","open_time","position","symbol","type","volume",
|
||||||
# Show all available columns in a logical order with friendly names
|
"open_price","sl","tp","market_price","swap","profit","comment"]
|
||||||
col_order = ["_account","position","symbol","symbol_base","type",
|
|
||||||
"volume","open_time","open_price","sl","tp","status"]
|
|
||||||
show_cols = [c for c in col_order if c in open_df.columns]
|
show_cols = [c for c in col_order if c in open_df.columns]
|
||||||
# Also append any unexpected extra columns the parser may return
|
|
||||||
show_cols += [c for c in open_df.columns if c not in show_cols]
|
|
||||||
|
|
||||||
rename_map = {
|
rename_map = {
|
||||||
"_account" : "Account",
|
"_account" : "Account",
|
||||||
"position" : "Position",
|
"open_time" : "Time",
|
||||||
"symbol" : "Symbol",
|
"position" : "Position",
|
||||||
"symbol_base": "Base",
|
"symbol" : "Symbol",
|
||||||
"type" : "Type",
|
"type" : "Type",
|
||||||
"volume" : "Lots",
|
"volume" : "Volume",
|
||||||
"open_time" : "Open Time",
|
"open_price" : "Price",
|
||||||
"open_price": "Open Price",
|
"sl" : "S/L",
|
||||||
"sl" : "SL",
|
"tp" : "T/P",
|
||||||
"tp" : "TP",
|
"market_price": "Market Price",
|
||||||
"status" : "Status",
|
"swap" : "Swap",
|
||||||
|
"profit" : "Profit",
|
||||||
|
"comment" : "Comment",
|
||||||
}
|
}
|
||||||
disp_df = open_df[show_cols].rename(columns=rename_map)
|
disp = open_df[show_cols].rename(columns=rename_map).copy()
|
||||||
if "Open Time" in disp_df.columns:
|
if "Time" in disp.columns:
|
||||||
disp_df["Open Time"] = pd.to_datetime(
|
disp["Time"] = pd.to_datetime(
|
||||||
disp_df["Open Time"], errors="coerce"
|
disp["Time"], errors="coerce"
|
||||||
).dt.strftime("%d.%m.%Y %H:%M")
|
).dt.strftime("%d.%m.%Y %H:%M")
|
||||||
|
|
||||||
with st.expander(f"🔴 Open Positions ({len(open_df)})", expanded=True):
|
with st.expander(f"🔴 Open Positions ({len(open_df)})", expanded=True):
|
||||||
st.dataframe(disp_df, use_container_width=True, hide_index=True)
|
st.dataframe(disp, use_container_width=True, hide_index=True)
|
||||||
else:
|
else:
|
||||||
st.caption("No open positions in current reports.")
|
st.caption("No open positions in current reports.")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user