Commit ·
ec289e0
1
Parent(s): 9e6eca5
feat(performance): Recently Closed Futures table (last 10, date/time closed) + /api/futures-closed proxy
Browse files- local_app.py +14 -0
- static/performance/index.html +72 -0
local_app.py
CHANGED
|
@@ -148,6 +148,7 @@ PUBLIC_PATHS_EXACT = (
|
|
| 148 |
'/api/balance-history',
|
| 149 |
'/api/funding-summary',
|
| 150 |
'/api/futures-positions',
|
|
|
|
| 151 |
'/robots.txt',
|
| 152 |
'/sitemap.xml',
|
| 153 |
'/llms.txt',
|
|
@@ -1180,6 +1181,19 @@ def bybit_balance_api():
|
|
| 1180 |
return jsonify({"status": "error", "message": str(e)[:120]}), 502
|
| 1181 |
|
| 1182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1183 |
@app.route('/api/futures-positions')
|
| 1184 |
def futures_positions_api():
|
| 1185 |
"""All open Bybit futures positions, proxied from the trader."""
|
|
|
|
| 148 |
'/api/balance-history',
|
| 149 |
'/api/funding-summary',
|
| 150 |
'/api/futures-positions',
|
| 151 |
+
'/api/futures-closed',
|
| 152 |
'/robots.txt',
|
| 153 |
'/sitemap.xml',
|
| 154 |
'/llms.txt',
|
|
|
|
| 1181 |
return jsonify({"status": "error", "message": str(e)[:120]}), 502
|
| 1182 |
|
| 1183 |
|
| 1184 |
+
@app.route('/api/futures-closed')
|
| 1185 |
+
def futures_closed_api():
|
| 1186 |
+
"""Last 10 closed futures positions, proxied from the trader."""
|
| 1187 |
+
try:
|
| 1188 |
+
r = requests.get(
|
| 1189 |
+
'https://scan.blind-monkeys.com/grid/futures-closed',
|
| 1190 |
+
timeout=90)
|
| 1191 |
+
r.raise_for_status()
|
| 1192 |
+
return Response(r.content, mimetype='application/json')
|
| 1193 |
+
except Exception as e:
|
| 1194 |
+
return jsonify({"status": "error", "message": str(e)[:120]}), 502
|
| 1195 |
+
|
| 1196 |
+
|
| 1197 |
@app.route('/api/futures-positions')
|
| 1198 |
def futures_positions_api():
|
| 1199 |
"""All open Bybit futures positions, proxied from the trader."""
|
static/performance/index.html
CHANGED
|
@@ -88,6 +88,27 @@
|
|
| 88 |
</table>
|
| 89 |
</div>
|
| 90 |
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
</div>
|
| 92 |
|
| 93 |
<script src="/css/nav.js?v=8"></script>
|
|
@@ -213,9 +234,54 @@
|
|
| 213 |
+ '<td></td></tr>';
|
| 214 |
}
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
document.querySelectorAll('th.sortable').forEach(function (th) {
|
| 217 |
th.addEventListener('click', function () {
|
| 218 |
var t = th.getAttribute('data-table'), k = th.getAttribute('data-key');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
if (SORT[t].key === k) SORT[t].dir = -SORT[t].dir;
|
| 220 |
else { SORT[t].key = k; SORT[t].dir = k === 'symbol' ? 1 : -1; }
|
| 221 |
if (t === 'grids') renderGrids(); else renderFut();
|
|
@@ -231,6 +297,12 @@
|
|
| 231 |
DATA.fut = Array.isArray(list) ? list : [];
|
| 232 |
renderFut();
|
| 233 |
}).catch(function () {});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
}
|
| 235 |
loadAll();
|
| 236 |
setInterval(loadAll, 60000);
|
|
|
|
| 88 |
</table>
|
| 89 |
</div>
|
| 90 |
</section>
|
| 91 |
+
|
| 92 |
+
<!-- Recently Closed Futures -->
|
| 93 |
+
<section class="grid-section">
|
| 94 |
+
<h2 class="grid-h2">🏁 Recently Closed Futures</h2>
|
| 95 |
+
<div class="table-wrap">
|
| 96 |
+
<table class="grid-table">
|
| 97 |
+
<thead><tr>
|
| 98 |
+
<th class="sortable" data-table="cfut" data-key="symbol">Symbol <span class="srt">↕</span></th>
|
| 99 |
+
<th class="sortable center" data-table="cfut" data-key="lev">Lev <span class="srt">↕</span></th>
|
| 100 |
+
<th class="sortable" data-table="cfut" data-key="invested">Invested <span class="srt">↕</span></th>
|
| 101 |
+
<th class="sortable" data-table="cfut" data-key="regime">Regime <span class="srt">↕</span></th>
|
| 102 |
+
<th class="sortable" data-table="cfut" data-key="funding">Funding Profit <span class="srt">↕</span></th>
|
| 103 |
+
<th class="sortable" data-table="cfut" data-key="realised">Unrealized <span class="srt">↕</span></th>
|
| 104 |
+
<th class="sortable" data-table="cfut" data-key="pnl">Total P&L <span class="srt">↕</span></th>
|
| 105 |
+
<th class="sortable" data-table="cfut" data-key="closed">Date/Time Closed <span class="srt">↕</span></th>
|
| 106 |
+
</tr></thead>
|
| 107 |
+
<tbody id="cfut-tbody"><tr><td colspan="8" class="muted">Loading…</td></tr></tbody>
|
| 108 |
+
<tfoot id="cfut-tfoot"></tfoot>
|
| 109 |
+
</table>
|
| 110 |
+
</div>
|
| 111 |
+
</section>
|
| 112 |
</div>
|
| 113 |
|
| 114 |
<script src="/css/nav.js?v=8"></script>
|
|
|
|
| 234 |
+ '<td></td></tr>';
|
| 235 |
}
|
| 236 |
|
| 237 |
+
var CFUT = [];
|
| 238 |
+
function renderCFut() {
|
| 239 |
+
var tb = document.getElementById('cfut-tbody');
|
| 240 |
+
var tf = document.getElementById('cfut-tfoot');
|
| 241 |
+
if (!CFUT.length) { tb.innerHTML = '<tr><td colspan="8" class="muted">No closed futures yet.</td></tr>'; tf.innerHTML = ''; return; }
|
| 242 |
+
tb.innerHTML = CFUT.map(function (p) {
|
| 243 |
+
var r = regimeName(p);
|
| 244 |
+
var rCls = r === 'Upward' ? 'pos' : (r === '—' ? 'mut' : 'neg');
|
| 245 |
+
var dt = p.closed_ms ? new Date(Number(p.closed_ms)) : null;
|
| 246 |
+
var dtTxt = dt ? dt.toLocaleDateString() + ' ' + dt.toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) : '—';
|
| 247 |
+
return '<tr>'
|
| 248 |
+
+ '<td style="font-weight:700;color:#58a6ff;">' + p.symbol + '</td>'
|
| 249 |
+
+ '<td class="center">' + (p.leverage || 1) + 'x</td>'
|
| 250 |
+
+ '<td>$' + num0(p.invested).toFixed(2) + '</td>'
|
| 251 |
+
+ '<td class="' + rCls + '">' + r + '</td>'
|
| 252 |
+
+ '<td class="' + pnlCls(p.funding_profit) + '">' + money(p.funding_profit) + '</td>'
|
| 253 |
+
+ '<td class="mut">—</td>'
|
| 254 |
+
+ '<td class="' + pnlCls(p.pnl) + '">' + money(p.pnl) + (num0(p.invested) > 0 ? ' (' + (num0(p.pnl) / num0(p.invested) * 100).toFixed(1) + '%)' : '') + '</td>'
|
| 255 |
+
+ '<td class="mut dur">' + dtTxt + '</td>'
|
| 256 |
+
+ '</tr>';
|
| 257 |
+
}).join('');
|
| 258 |
+
var tPnl = 0, tInv = 0;
|
| 259 |
+
CFUT.forEach(function (p) { tPnl += num0(p.pnl); tInv += num0(p.invested); });
|
| 260 |
+
tf.innerHTML = '<tr><td>Total (' + CFUT.length + ')</td><td></td>'
|
| 261 |
+
+ '<td>$' + tInv.toFixed(2) + '</td><td></td><td></td><td></td>'
|
| 262 |
+
+ '<td class="' + pnlCls(tPnl) + '">' + money(tPnl) + '</td><td></td></tr>';
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
document.querySelectorAll('th.sortable').forEach(function (th) {
|
| 266 |
th.addEventListener('click', function () {
|
| 267 |
var t = th.getAttribute('data-table'), k = th.getAttribute('data-key');
|
| 268 |
+
if (t === 'cfut') {
|
| 269 |
+
if (!window._cfutSort || window._cfutSort.k !== k) window._cfutSort = { k: k, dir: k === 'symbol' ? 1 : -1 };
|
| 270 |
+
else window._cfutSort.dir = -window._cfutSort.dir;
|
| 271 |
+
var g = {
|
| 272 |
+
symbol: function (p) { return p.symbol || ''; },
|
| 273 |
+
lev: function (p) { return Number(p.leverage || 1); },
|
| 274 |
+
invested: function (p) { return num0(p.invested); },
|
| 275 |
+
regime: function (p) { return regimeName(p); },
|
| 276 |
+
funding: function (p) { return num0(p.funding_profit); },
|
| 277 |
+
realised: function (p) { return 0; },
|
| 278 |
+
pnl: function (p) { return num0(p.pnl); },
|
| 279 |
+
closed: function (p) { return Number(p.closed_ms) || 0; }
|
| 280 |
+
}[k];
|
| 281 |
+
if (g) CFUT.sort(function (a, b) { var av = g(a), bv = g(b); return (av < bv ? -1 : av > bv ? 1 : 0) * window._cfutSort.dir; });
|
| 282 |
+
renderCFut();
|
| 283 |
+
return;
|
| 284 |
+
}
|
| 285 |
if (SORT[t].key === k) SORT[t].dir = -SORT[t].dir;
|
| 286 |
else { SORT[t].key = k; SORT[t].dir = k === 'symbol' ? 1 : -1; }
|
| 287 |
if (t === 'grids') renderGrids(); else renderFut();
|
|
|
|
| 297 |
DATA.fut = Array.isArray(list) ? list : [];
|
| 298 |
renderFut();
|
| 299 |
}).catch(function () {});
|
| 300 |
+
fetch('/api/futures-closed').then(function (r) { return r.json(); }).then(function (list) {
|
| 301 |
+
CFUT = (Array.isArray(list) ? list : []).slice().sort(function (a, b) {
|
| 302 |
+
return (Number(b.closed_ms) || 0) - (Number(a.closed_ms) || 0);
|
| 303 |
+
});
|
| 304 |
+
renderCFut();
|
| 305 |
+
}).catch(function () { renderCFut(); });
|
| 306 |
}
|
| 307 |
loadAll();
|
| 308 |
setInterval(loadAll, 60000);
|