Commit ·
d98ca71
1
Parent(s): 821dfa1
Add Date + Investment columns, link bot name to /bot/<id>
Browse files- bybit_pnl_snapshot.py +2 -0
- local_app.py +4 -0
- templates/dart_performance.html +18 -2
bybit_pnl_snapshot.py
CHANGED
|
@@ -119,6 +119,7 @@ for b in bots_history.get("bots", []):
|
|
| 119 |
b["final_pnl"] = float(snap.get("total_pnl", 0))
|
| 120 |
b["final_pnl_per"] = float(snap.get("total_pnl_per", 0))
|
| 121 |
b["equity"] = float(snap.get("equity", 0))
|
|
|
|
| 122 |
b["last_seen"] = now_ts
|
| 123 |
b["status"] = "running"
|
| 124 |
found = True
|
|
@@ -133,6 +134,7 @@ if not found:
|
|
| 133 |
"final_pnl": float(snap.get("total_pnl", 0)),
|
| 134 |
"final_pnl_per": float(snap.get("total_pnl_per", 0)),
|
| 135 |
"equity": float(snap.get("equity", 0)),
|
|
|
|
| 136 |
"first_seen": now_ts,
|
| 137 |
"last_seen": now_ts,
|
| 138 |
"status": "running",
|
|
|
|
| 119 |
b["final_pnl"] = float(snap.get("total_pnl", 0))
|
| 120 |
b["final_pnl_per"] = float(snap.get("total_pnl_per", 0))
|
| 121 |
b["equity"] = float(snap.get("equity", 0))
|
| 122 |
+
b["investment"] = float(snap.get("total_margin", 0) or 0)
|
| 123 |
b["last_seen"] = now_ts
|
| 124 |
b["status"] = "running"
|
| 125 |
found = True
|
|
|
|
| 134 |
"final_pnl": float(snap.get("total_pnl", 0)),
|
| 135 |
"final_pnl_per": float(snap.get("total_pnl_per", 0)),
|
| 136 |
"equity": float(snap.get("equity", 0)),
|
| 137 |
+
"investment": float(snap.get("total_margin", 0) or 0),
|
| 138 |
"first_seen": now_ts,
|
| 139 |
"last_seen": now_ts,
|
| 140 |
"status": "running",
|
local_app.py
CHANGED
|
@@ -1095,14 +1095,18 @@ def bot_history_api():
|
|
| 1095 |
"cumulative_pnl": round(cumulative_pnl, 4),
|
| 1096 |
"create_time": b.get("create_time"),
|
| 1097 |
"end_time": b.get("end_time"),
|
|
|
|
| 1098 |
})
|
| 1099 |
|
|
|
|
|
|
|
| 1100 |
resp = jsonify({
|
| 1101 |
"status": "ok",
|
| 1102 |
"bots": out,
|
| 1103 |
"total_bots": len(out),
|
| 1104 |
"cumulative_pnl": round(cumulative_pnl, 4),
|
| 1105 |
"total_hours": round(total_seconds / 3600.0, 2),
|
|
|
|
| 1106 |
})
|
| 1107 |
resp.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
| 1108 |
return resp
|
|
|
|
| 1095 |
"cumulative_pnl": round(cumulative_pnl, 4),
|
| 1096 |
"create_time": b.get("create_time"),
|
| 1097 |
"end_time": b.get("end_time"),
|
| 1098 |
+
"investment": round(float(b.get("investment", 0) or 0), 2),
|
| 1099 |
})
|
| 1100 |
|
| 1101 |
+
total_investment = sum(float(b.get("investment", 0) or 0) for b in out)
|
| 1102 |
+
|
| 1103 |
resp = jsonify({
|
| 1104 |
"status": "ok",
|
| 1105 |
"bots": out,
|
| 1106 |
"total_bots": len(out),
|
| 1107 |
"cumulative_pnl": round(cumulative_pnl, 4),
|
| 1108 |
"total_hours": round(total_seconds / 3600.0, 2),
|
| 1109 |
+
"total_investment": round(total_investment, 2),
|
| 1110 |
})
|
| 1111 |
resp.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
| 1112 |
return resp
|
templates/dart_performance.html
CHANGED
|
@@ -18,6 +18,8 @@
|
|
| 18 |
.num { font-family: 'SF Mono', Monaco, monospace; text-align: right; }
|
| 19 |
.bot-id { font-family: 'SF Mono', Monaco, monospace; font-size: 12px; color: #8b949e; }
|
| 20 |
.bot-name { color: #e6edf3; font-weight: 600; }
|
|
|
|
|
|
|
| 21 |
.positive { color: #4ade80; }
|
| 22 |
.negative { color: #f87171; }
|
| 23 |
.neutral { color: #8b949e; }
|
|
@@ -40,6 +42,14 @@
|
|
| 40 |
</div>
|
| 41 |
|
| 42 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
function fmtDuration(seconds) {
|
| 44 |
var hours = seconds / 3600.0;
|
| 45 |
return hours.toFixed(2) + ' hrs';
|
|
@@ -65,7 +75,9 @@
|
|
| 65 |
}
|
| 66 |
var html = '<table>';
|
| 67 |
html += '<thead><tr>';
|
| 68 |
-
html += '<th>Bot
|
|
|
|
|
|
|
| 69 |
html += '<th>Duration</th>';
|
| 70 |
html += '<th class="num">Net P/L %</th>';
|
| 71 |
html += '<th class="num">Cumulative P/L</th>';
|
|
@@ -73,8 +85,10 @@
|
|
| 73 |
|
| 74 |
data.bots.forEach(function(b) {
|
| 75 |
html += '<tr>';
|
| 76 |
-
html += '<td><div class="bot-name">' + (b.bot_name || 'Unnamed') + '</div>';
|
| 77 |
html += '<div class="bot-id">' + b.bot_id + ' · <span class="status-' + b.status + '">' + b.status + '</span></div></td>';
|
|
|
|
|
|
|
| 78 |
html += '<td class="num">' + fmtDuration(b.duration_seconds) + '</td>';
|
| 79 |
html += '<td class="num ' + cls(b.pnl_per) + '">' + fmtPct(b.pnl_per) + '</td>';
|
| 80 |
html += '<td class="num ' + cls(b.cumulative_pnl) + '">' + fmtPnl(b.cumulative_pnl) + '</td>';
|
|
@@ -84,6 +98,8 @@
|
|
| 84 |
// Totals row
|
| 85 |
html += '<tr class="totals-row">';
|
| 86 |
html += '<td>TOTAL (' + data.total_bots + ' bot' + (data.total_bots === 1 ? '' : 's') + ')</td>';
|
|
|
|
|
|
|
| 87 |
html += '<td class="num">' + data.total_hours.toFixed(2) + ' hrs</td>';
|
| 88 |
html += '<td class="num">—</td>';
|
| 89 |
html += '<td class="num ' + cls(data.cumulative_pnl) + '">' + fmtPnl(data.cumulative_pnl) + '</td>';
|
|
|
|
| 18 |
.num { font-family: 'SF Mono', Monaco, monospace; text-align: right; }
|
| 19 |
.bot-id { font-family: 'SF Mono', Monaco, monospace; font-size: 12px; color: #8b949e; }
|
| 20 |
.bot-name { color: #e6edf3; font-weight: 600; }
|
| 21 |
+
.bot-link { text-decoration: none; }
|
| 22 |
+
.bot-link:hover .bot-name { color: #f0b90b; text-decoration: underline; }
|
| 23 |
.positive { color: #4ade80; }
|
| 24 |
.negative { color: #f87171; }
|
| 25 |
.neutral { color: #8b949e; }
|
|
|
|
| 42 |
</div>
|
| 43 |
|
| 44 |
<script>
|
| 45 |
+
function fmtDate(ts) {
|
| 46 |
+
if (!ts) return '—';
|
| 47 |
+
var d = new Date(ts * 1000);
|
| 48 |
+
var y = d.getFullYear();
|
| 49 |
+
var m = ('0' + (d.getMonth() + 1)).slice(-2);
|
| 50 |
+
var day = ('0' + d.getDate()).slice(-2);
|
| 51 |
+
return y + '-' + m + '-' + day;
|
| 52 |
+
}
|
| 53 |
function fmtDuration(seconds) {
|
| 54 |
var hours = seconds / 3600.0;
|
| 55 |
return hours.toFixed(2) + ' hrs';
|
|
|
|
| 75 |
}
|
| 76 |
var html = '<table>';
|
| 77 |
html += '<thead><tr>';
|
| 78 |
+
html += '<th>Bot</th>';
|
| 79 |
+
html += '<th>Date</th>';
|
| 80 |
+
html += '<th class="num">Investment</th>';
|
| 81 |
html += '<th>Duration</th>';
|
| 82 |
html += '<th class="num">Net P/L %</th>';
|
| 83 |
html += '<th class="num">Cumulative P/L</th>';
|
|
|
|
| 85 |
|
| 86 |
data.bots.forEach(function(b) {
|
| 87 |
html += '<tr>';
|
| 88 |
+
html += '<td><a href="/bot/' + b.bot_id + '" class="bot-link"><div class="bot-name">' + (b.bot_name || 'Unnamed') + '</div></a>';
|
| 89 |
html += '<div class="bot-id">' + b.bot_id + ' · <span class="status-' + b.status + '">' + b.status + '</span></div></td>';
|
| 90 |
+
html += '<td>' + fmtDate(b.create_time) + '</td>';
|
| 91 |
+
html += '<td class="num">' + (b.investment ? '$' + b.investment.toFixed(2) : '—') + '</td>';
|
| 92 |
html += '<td class="num">' + fmtDuration(b.duration_seconds) + '</td>';
|
| 93 |
html += '<td class="num ' + cls(b.pnl_per) + '">' + fmtPct(b.pnl_per) + '</td>';
|
| 94 |
html += '<td class="num ' + cls(b.cumulative_pnl) + '">' + fmtPnl(b.cumulative_pnl) + '</td>';
|
|
|
|
| 98 |
// Totals row
|
| 99 |
html += '<tr class="totals-row">';
|
| 100 |
html += '<td>TOTAL (' + data.total_bots + ' bot' + (data.total_bots === 1 ? '' : 's') + ')</td>';
|
| 101 |
+
html += '<td>—</td>';
|
| 102 |
+
html += '<td class="num">' + (data.total_investment ? '$' + data.total_investment.toFixed(2) : '—') + '</td>';
|
| 103 |
html += '<td class="num">' + data.total_hours.toFixed(2) + ' hrs</td>';
|
| 104 |
html += '<td class="num">—</td>';
|
| 105 |
html += '<td class="num ' + cls(data.cumulative_pnl) + '">' + fmtPnl(data.cumulative_pnl) + '</td>';
|