forked from minculusofia-wq/Ironvault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_logs.py
More file actions
111 lines (90 loc) · 3.29 KB
/
analyze_logs.py
File metadata and controls
111 lines (90 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
"""
Log Analysis Tool for IRONVAULT
Parses audit logs to summarize paper trading performance.
"""
import os
import re
import ast
import sys
from pathlib import Path
from datetime import datetime
LOG_DIR = Path("logs")
def find_latest_log():
if not LOG_DIR.exists():
return None
files = list(LOG_DIR.glob("audit_*.log"))
if not files:
return None
# Sort by name (which includes timestamp)
return sorted(files)[-1]
def parse_log_line(line):
# Format: YYYY-MM-DD HH:MM:SS | INFO | {json-like dict}
try:
parts = line.split(" | ", 2)
if len(parts) < 3:
return None
timestamp_str = parts[0]
# details part is a string representation of a dict
details_str = parts[2].strip()
# safely evaluate the dict string
data = ast.literal_eval(details_str)
return {"timestamp": timestamp_str, "data": data}
except Exception:
return None
def analyze_logs(log_file):
print(f"📊 Analyzing log file: {log_file}")
trades = []
errors = 0
with open(log_file, 'r', encoding='utf-8') as f:
for line in f:
entry = parse_log_line(line)
if not entry:
continue
data = entry["data"]
event_type = data.get("type")
action = data.get("action")
details = data.get("details", {})
if action == "PAPER_TRADE_EXECUTED":
trades.append({
"time": entry["timestamp"],
"strategy": details.get("strategy", "Unknown"),
"order_id": details.get("order_id"),
"params": details.get("params", {})
})
elif event_type == "SYSTEM_ERROR" or event_type == "POLICY_VIOLATION":
errors += 1
# Summary
print(f"\n--- 📝 Paper Trading Summary ---")
print(f"Total Trades Simulated: {len(trades)}")
print(f"Errors/Violations Logged: {errors}")
if not trades:
print("\nNo paper trades found yet. Make sure the bot is RUNNING and strategies are active.")
return
print(f"\n--- 📋 Trade Details ---")
by_strategy = {}
for t in trades:
strat = t["strategy"]
if strat not in by_strategy:
by_strategy[strat] = []
by_strategy[strat].append(t)
params = t["params"]
side = params.get("side", "BUY")
size = float(params.get("size", 0))
price = float(params.get("price", 0))
token = params.get("token_id", "???")[:10] + "..."
print(f"[{t['time']}] {strat} | {side} {size} @ {price} | Token: {token}")
print(f"\n--- 📈 Strategy Breakdown ---")
for strat, t_list in by_strategy.items():
count = len(t_list)
total_vol = sum(float(t["params"].get("size", 0)) * float(t["params"].get("price", 0)) for t in t_list)
print(f"{strat}: {count} trades | Est. Volume: ${total_vol:.2f}")
if __name__ == "__main__":
if len(sys.argv) > 1:
log_file = sys.argv[1]
else:
log_file = find_latest_log()
if not log_file:
print("❌ No log files found in logs/ directory.")
else:
analyze_logs(log_file)