Add read-report utility to parse HTML directly
- read-report.sh: Bash wrapper to find and read report - parse-html-report.py: Python parser for MT5 HTML reports - Reads directly from Wine Desktop location - Displays formatted report in terminal - Shows browser access URL
This commit is contained in:
143
parse-html-report.py
Executable file
143
parse-html-report.py
Executable file
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Parse MT5 HTML report and display formatted output"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
def parse_report(html_file):
|
||||
try:
|
||||
with open(html_file, 'rb') as f:
|
||||
content = f.read().decode('utf-16-le', errors='ignore')
|
||||
except Exception as e:
|
||||
print(f"Error reading file: {e}")
|
||||
return None
|
||||
|
||||
# Clean text
|
||||
text = re.sub('<[^<]+?>', ' ', content)
|
||||
text = text.replace(' ', ' ')
|
||||
|
||||
def extract_value(pattern, text, group=1):
|
||||
match = re.search(pattern, text)
|
||||
return match.group(group).strip() if match else None
|
||||
|
||||
def parse_num(s):
|
||||
if not s:
|
||||
return 0
|
||||
try:
|
||||
s = str(s).replace(' ', '').replace(',', '.')
|
||||
parts = s.split('.')
|
||||
if len(parts) > 2:
|
||||
s = ''.join(parts[:-1]) + '.' + parts[-1]
|
||||
return float(s)
|
||||
except:
|
||||
return 0
|
||||
|
||||
# Extract account number from filename
|
||||
account_num = os.path.basename(html_file).split('-')[1].split('.')[0] if '-' in html_file else 'Unknown'
|
||||
|
||||
# Color codes
|
||||
GREEN = '\033[0;32m'
|
||||
YELLOW = '\033[1;33m'
|
||||
RED = '\033[0;31m'
|
||||
BLUE = '\033[0;34m'
|
||||
NC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
|
||||
print(f"{BOLD}{'='*70}{NC}")
|
||||
print(f"{BOLD} MT5 TRADING REPORT - Account {account_num}{NC}")
|
||||
print(f"{BOLD}{'='*70}{NC}")
|
||||
|
||||
# Extract data
|
||||
name = extract_value(r'Name:\s*([^\d]+?)(?:\s+Account|\s*$)', text)
|
||||
company = extract_value(r'Company:\s*([^\d]+?)(?:\s+Date|\s*$)', text)
|
||||
net_profit = extract_value(r'Total Net Profit[^\d\-]*([\-\d\s,\.]+)', text)
|
||||
gross_profit = extract_value(r'Gross Profit[^\d]*([\d\s,\.]+)', text)
|
||||
gross_loss = extract_value(r'Gross Loss[^\d\-]*([\-\d\s,\.]+)', text)
|
||||
profit_factor = extract_value(r'Profit Factor[^\d]*([\d\.]+)', text)
|
||||
total_trades = extract_value(r'Total Trades[^\d]*(\d+)', text)
|
||||
profit_trades = extract_value(r'Profit Trades \(%[^)]*\)[^\d]*(\d+)', text)
|
||||
loss_trades = extract_value(r'Loss Trades \(%[^)]*\)[^\d]*(\d+)', text)
|
||||
win_pct = extract_value(r'Profit Trades \(%[^)]*\)[^\d]*\d+[^\d]*\((\d+\.?\d*)%', text)
|
||||
largest_profit = extract_value(r'Largest profit trade[^\d]*([\d\s,\.]+)', text)
|
||||
largest_loss = extract_value(r'Largest loss trade[^\d\-]*([\-\d\s,\.]+)', text)
|
||||
|
||||
print(f"\n{BLUE}📊 ACCOUNT INFORMATION{NC}")
|
||||
print("-" * 50)
|
||||
if name:
|
||||
print(f"Name: {name}")
|
||||
if company:
|
||||
print(f"Company: {company}")
|
||||
print(f"Account: {account_num}")
|
||||
|
||||
print(f"\n{GREEN}💰 FINANCIAL RESULTS{NC}")
|
||||
print("-" * 50)
|
||||
|
||||
if net_profit:
|
||||
val = parse_num(net_profit)
|
||||
color = GREEN if val > 0 else RED
|
||||
print(f"{color}Total Net Profit: ${val:>12,.2f}{NC}")
|
||||
|
||||
if gross_profit:
|
||||
val = parse_num(gross_profit)
|
||||
print(f"Gross Profit: ${val:>12,.2f}")
|
||||
|
||||
if gross_loss:
|
||||
val = parse_num(gross_loss)
|
||||
print(f"Gross Loss: ${val:>12,.2f}")
|
||||
|
||||
if profit_factor:
|
||||
val = parse_num(profit_factor)
|
||||
color = GREEN if val > 1.5 else YELLOW if val > 1 else RED
|
||||
print(f"{color}Profit Factor: {val:>12.2f}{NC}")
|
||||
|
||||
print(f"\n{YELLOW}📈 TRADE STATISTICS{NC}")
|
||||
print("-" * 50)
|
||||
|
||||
if total_trades:
|
||||
print(f"Total Trades: {total_trades:>12}")
|
||||
if profit_trades:
|
||||
print(f"{GREEN}Winning Trades: {profit_trades:>12}{NC}")
|
||||
if loss_trades:
|
||||
print(f"{RED}Losing Trades: {loss_trades:>12}{NC}")
|
||||
if win_pct:
|
||||
val = parse_num(win_pct)
|
||||
color = GREEN if val > 60 else YELLOW if val > 40 else RED
|
||||
print(f"{color}Win Rate: {val:>11.2f}%{NC}")
|
||||
if largest_profit:
|
||||
val = parse_num(largest_profit)
|
||||
print(f"Largest Win: ${val:>12,.2f}")
|
||||
if largest_loss:
|
||||
val = parse_num(largest_loss)
|
||||
print(f"Largest Loss: ${val:>12,.2f}")
|
||||
|
||||
# Calculate return
|
||||
if net_profit:
|
||||
profit = parse_num(net_profit)
|
||||
return_pct = (profit / 100000) * 100
|
||||
|
||||
print(f"\n{BOLD}{'='*70}{NC}")
|
||||
print(f"{BOLD} STARTING BALANCE: $100,000.00{NC}")
|
||||
print(f"{GREEN}{BOLD} CURRENT BALANCE: ${100000 + profit:>12,.2f}{NC}")
|
||||
print(f"{GREEN}{BOLD} NET PROFIT: ${profit:>12,.2f}{NC}")
|
||||
color = GREEN if return_pct > 0 else RED
|
||||
print(f"{color}{BOLD} RETURN: {return_pct:>11.2f}%{NC}")
|
||||
print(f"{BOLD}{'='*70}{NC}")
|
||||
|
||||
print(f"\n{BLUE}🎯 STRATEGY{NC}")
|
||||
print("-" * 50)
|
||||
print("EA: MultiSignal Confluence EA")
|
||||
print("Note: This is HTML report data (may be outdated)")
|
||||
print(" Check MT5 terminal for live/current data")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
parse_report(sys.argv[1])
|
||||
else:
|
||||
# Default report
|
||||
report_file = os.path.expanduser("~/mt5-docker/config/.wine/drive_c/users/abc/Desktop/ReportHistory-104125640.html")
|
||||
if os.path.exists(report_file):
|
||||
parse_report(report_file)
|
||||
else:
|
||||
print("No report file found!")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user