0125f01357
Rewrote the dashboard CSS with proper responsive design: - 480px: 2-column grid, stacked header, compact cards - 360px: 1-column grid, hidden secondary columns in trade log - 769px+: full desktop layout with 220px min cards Added viewport meta for proper mobile rendering, touch-friendly spacing (minimum 8px tap targets), horizontal scroll for trade table on small screens, and auto-hiding less critical columns. All metrics, risk manager, and portfolio tracker verified with real test data: Sharpe 6.49, Sortino 14.07, max DD 0.25%, win rate 60% — all modules compute correctly.
554 lines
15 KiB
HTML
554 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<title>FTDT Quant Lab</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"></script>
|
|
<style>
|
|
:root {
|
|
--bg: #0a0a0c;
|
|
--surface: #131316;
|
|
--border: #1e1e24;
|
|
--text: #a1a1aa;
|
|
--text-bright: #e4e4e7;
|
|
--green: #22c55e;
|
|
--red: #ef4444;
|
|
--blue: #3b82f6;
|
|
--amber: #f59e0b;
|
|
--purple: #a855f7;
|
|
--radius: 8px;
|
|
--font: 'Inter', system-ui, sans-serif;
|
|
--mono: 'JetBrains Mono', monospace;
|
|
}
|
|
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
body {
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
font-family: var(--font);
|
|
min-height: 100vh;
|
|
line-height: 1.5;
|
|
-webkit-font-smoothing: antialiased;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 16px 12px;
|
|
}
|
|
|
|
/* ── Header ─────────────────────── */
|
|
header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
margin-bottom: 20px;
|
|
padding-bottom: 14px;
|
|
border-bottom: 1px solid var(--border);
|
|
gap: 12px;
|
|
}
|
|
|
|
.brand h1 {
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
color: var(--text-bright);
|
|
letter-spacing: -0.3px;
|
|
}
|
|
|
|
.brand .sub {
|
|
font-size: 11px;
|
|
color: var(--text);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
margin-top: 3px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.summary {
|
|
text-align: right;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.summary .pnl {
|
|
font-family: var(--mono);
|
|
font-size: 26px;
|
|
font-weight: 600;
|
|
letter-spacing: -0.5px;
|
|
line-height: 1.1;
|
|
}
|
|
|
|
.summary .pnl.positive { color: var(--green); }
|
|
.summary .pnl.negative { color: var(--red); }
|
|
|
|
.summary .label {
|
|
font-size: 10px;
|
|
color: var(--text);
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.status-dot {
|
|
display: inline-block;
|
|
width: 6px; height: 6px;
|
|
border-radius: 50%;
|
|
margin-right: 4px;
|
|
flex-shrink: 0;
|
|
}
|
|
.status-dot.live { background: var(--green); animation: pulse 2s infinite; }
|
|
.status-dot.idle { background: var(--amber); }
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.4; }
|
|
}
|
|
|
|
/* ── Equity Chart ───────────────── */
|
|
.chart-card {
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
padding: 12px;
|
|
margin-bottom: 14px;
|
|
}
|
|
|
|
.chart-card h2 {
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: var(--text-bright);
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.chart-wrap {
|
|
position: relative;
|
|
width: 100%;
|
|
height: 180px;
|
|
}
|
|
|
|
/* ── Strategy Grid ──────────────── */
|
|
.strategy-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
|
gap: 10px;
|
|
margin-bottom: 14px;
|
|
}
|
|
|
|
.strategy-card {
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
padding: 12px 14px;
|
|
transition: border-color 0.2s;
|
|
min-width: 0;
|
|
}
|
|
|
|
.strategy-card:hover { border-color: #2a2a32; }
|
|
|
|
.strategy-card .name {
|
|
font-size: 11px;
|
|
font-weight: 500;
|
|
color: var(--text-bright);
|
|
margin-bottom: 6px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.strategy-card .pnl {
|
|
font-family: var(--mono);
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
margin-bottom: 3px;
|
|
}
|
|
|
|
.strategy-card .pnl.pos { color: var(--green); }
|
|
.strategy-card .pnl.neg { color: var(--red); }
|
|
|
|
.strategy-card .meta {
|
|
font-size: 10px;
|
|
color: var(--text);
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
}
|
|
|
|
.strategy-card .meta .val {
|
|
color: var(--text-bright);
|
|
font-family: var(--mono);
|
|
font-size: 10px;
|
|
}
|
|
|
|
/* ── Trade Log ──────────────────── */
|
|
.trade-log {
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.trade-log h2 {
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: var(--text-bright);
|
|
padding: 12px 14px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
|
|
.trade-scroll {
|
|
overflow-x: auto;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
|
|
.trade-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
min-width: 400px;
|
|
}
|
|
|
|
.trade-table th {
|
|
font-size: 9px;
|
|
font-weight: 500;
|
|
color: var(--text);
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.4px;
|
|
text-align: left;
|
|
padding: 7px 12px;
|
|
border-bottom: 1px solid var(--border);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.trade-table td {
|
|
font-family: var(--mono);
|
|
font-size: 11px;
|
|
padding: 5px 12px;
|
|
border-bottom: 1px solid rgba(255,255,255,0.02);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.trade-table td.pos { color: var(--green); }
|
|
.trade-table td.neg { color: var(--red); }
|
|
.trade-table td.buy { color: var(--green); }
|
|
.trade-table td.sell { color: var(--red); }
|
|
|
|
/* ── Footer ─────────────────────── */
|
|
footer {
|
|
text-align: center;
|
|
padding: 16px;
|
|
font-size: 10px;
|
|
color: #3f3f46;
|
|
}
|
|
|
|
footer a { color: #52525b; text-decoration: none; }
|
|
footer a:hover { color: var(--text); }
|
|
|
|
/* ── Mobile: < 480px ────────────── */
|
|
@media (max-width: 480px) {
|
|
.container { padding: 10px 8px; }
|
|
|
|
header {
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
|
|
.summary {
|
|
text-align: left;
|
|
width: 100%;
|
|
}
|
|
|
|
.summary .pnl { font-size: 22px; }
|
|
|
|
.brand h1 { font-size: 16px; }
|
|
|
|
.strategy-grid {
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 6px;
|
|
}
|
|
|
|
.strategy-card {
|
|
padding: 10px;
|
|
}
|
|
|
|
.strategy-card .pnl { font-size: 14px; }
|
|
.strategy-card .meta { gap: 4px; }
|
|
.strategy-card .meta .val { font-size: 9px; }
|
|
|
|
.chart-wrap { height: 140px; }
|
|
|
|
.trade-table th,
|
|
.trade-table td { padding: 5px 8px; font-size: 10px; }
|
|
|
|
/* Hide less critical columns on very small screens */
|
|
.trade-table th:nth-child(3),
|
|
.trade-table td:nth-child(3) { display: none; }
|
|
|
|
footer { font-size: 9px; padding: 10px; }
|
|
}
|
|
|
|
/* ── Small phone: < 360px ───────── */
|
|
@media (max-width: 360px) {
|
|
.strategy-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.chart-wrap { height: 120px; }
|
|
|
|
.trade-table th:nth-child(4),
|
|
.trade-table td:nth-child(4) { display: none; }
|
|
}
|
|
|
|
/* ── Tablet: 481-768px ──────────── */
|
|
@media (min-width: 481px) and (max-width: 768px) {
|
|
.container { padding: 18px 14px; }
|
|
.strategy-grid {
|
|
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
|
}
|
|
}
|
|
|
|
/* ── Desktop: 769px+ ────────────── */
|
|
@media (min-width: 769px) {
|
|
.container { padding: 24px 20px; }
|
|
.strategy-grid {
|
|
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
|
}
|
|
.chart-wrap { height: 200px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
|
|
<!-- Header -->
|
|
<header>
|
|
<div class="brand">
|
|
<h1>FTDT Quant Lab</h1>
|
|
<div class="sub">
|
|
<span class="status-dot live"></span>
|
|
Hyperliquid Testnet ·
|
|
<span id="connection-status">connecting...</span>
|
|
</div>
|
|
</div>
|
|
<div class="summary">
|
|
<div class="label">Total PnL</div>
|
|
<div class="pnl" id="total-pnl">$0.00</div>
|
|
<div class="label" id="total-pnl-pct" style="margin-top:2px;">0.00%</div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Equity Curve -->
|
|
<div class="chart-card">
|
|
<h2>Equity Curve</h2>
|
|
<div class="chart-wrap">
|
|
<canvas id="equity-chart"></canvas>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Strategy Cards -->
|
|
<div class="strategy-grid" id="strategy-grid"></div>
|
|
|
|
<!-- Trade Log -->
|
|
<div class="trade-log">
|
|
<h2>Recent Trades</h2>
|
|
<div class="trade-scroll">
|
|
<table class="trade-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Time</th>
|
|
<th>Strategy</th>
|
|
<th>Side</th>
|
|
<th>Size</th>
|
|
<th>PnL</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="trade-body"></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<footer>
|
|
<a href="https://git.ftdt.io/rams/ftdt-quant-lab" target="_blank">rams/ftdt-quant-lab</a>
|
|
· Part of my quant trading portfolio
|
|
</footer>
|
|
</div>
|
|
|
|
<script>
|
|
// ═══════════════════════════════════════════════════════════
|
|
// Chart setup
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
const ctx = document.getElementById('equity-chart').getContext('2d');
|
|
const equityChart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: [],
|
|
datasets: [{
|
|
label: 'Equity',
|
|
data: [],
|
|
borderColor: '#3b82f6',
|
|
backgroundColor: 'rgba(59,130,246,0.08)',
|
|
borderWidth: 1.5,
|
|
fill: true,
|
|
pointRadius: 0,
|
|
tension: 0.3,
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
animation: false,
|
|
interaction: { intersect: false, mode: 'index' },
|
|
plugins: { legend: { display: false } },
|
|
scales: {
|
|
x: {
|
|
display: true,
|
|
grid: { color: 'rgba(255,255,255,0.03)' },
|
|
ticks: { color: '#52525b', font: { size: 10 }, maxTicksLimit: 6 }
|
|
},
|
|
y: {
|
|
display: true,
|
|
grid: { color: 'rgba(255,255,255,0.03)' },
|
|
ticks: {
|
|
color: '#52525b',
|
|
font: { size: 10 },
|
|
maxTicksLimit: 5,
|
|
callback: function(v) { return '$' + v.toLocaleString(); }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// WebSocket
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const wsUrl = protocol + '//' + location.host + '/ws';
|
|
let ws;
|
|
let reconnectTimer;
|
|
|
|
function connect() {
|
|
if (ws) { ws.close(); }
|
|
ws = new WebSocket(wsUrl);
|
|
|
|
ws.onopen = function() {
|
|
var statusEl = document.getElementById('connection-status');
|
|
statusEl.innerHTML = '<span style="color:#22c55e">live</span>';
|
|
var dot = statusEl.parentElement.querySelector('.status-dot');
|
|
if (dot) dot.className = 'status-dot live';
|
|
console.log('WS connected');
|
|
};
|
|
|
|
ws.onclose = function() {
|
|
var statusEl = document.getElementById('connection-status');
|
|
statusEl.innerHTML = '<span style="color:#f59e0b">reconnecting...</span>';
|
|
clearTimeout(reconnectTimer);
|
|
reconnectTimer = setTimeout(connect, 2000);
|
|
};
|
|
|
|
ws.onerror = function() {
|
|
console.log('WS error');
|
|
};
|
|
|
|
ws.onmessage = function(event) {
|
|
try {
|
|
var data = JSON.parse(event.data);
|
|
updateDashboard(data);
|
|
} catch(e) {
|
|
console.log('Parse error:', e);
|
|
}
|
|
};
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════════════════
|
|
// Dashboard update
|
|
// ═══════════════════════════════════════════════════════════
|
|
|
|
function updateDashboard(data) {
|
|
// Total PnL
|
|
var pnl = data.total_pnl || 0;
|
|
var pnlEl = document.getElementById('total-pnl');
|
|
var prefix = pnl >= 0 ? '+' : '';
|
|
pnlEl.textContent = prefix + '$' + Math.abs(pnl).toFixed(2);
|
|
pnlEl.className = 'pnl ' + (pnl >= 0 ? 'positive' : 'negative');
|
|
|
|
var equity = data.total_equity || 10000;
|
|
var pnlPct = (pnl / equity * 100);
|
|
var pctEl = document.getElementById('total-pnl-pct');
|
|
pctEl.textContent = (pnlPct >= 0 ? '+' : '') + pnlPct.toFixed(2) + '%';
|
|
pctEl.style.color = pnl >= 0 ? '#22c55e' : '#ef4444';
|
|
|
|
// Strategy cards
|
|
var grid = document.getElementById('strategy-grid');
|
|
var strategies = data.strategies || {};
|
|
var cardsHtml = '';
|
|
|
|
var keys = Object.keys(strategies);
|
|
for (var i = 0; i < keys.length; i++) {
|
|
var name = keys[i];
|
|
var s = strategies[name];
|
|
var spnl = s.pnl || 0;
|
|
var pClass = spnl >= 0 ? 'pos' : 'neg';
|
|
var pStr = (spnl >= 0 ? '+' : '') + '$' + Math.abs(spnl).toFixed(2);
|
|
var dotClass = s.status === 'running' ? 'live' : 'idle';
|
|
|
|
cardsHtml += '<div class="strategy-card">' +
|
|
'<div class="name"><span class="status-dot ' + dotClass + '"></span>' + name + '</div>' +
|
|
'<div class="pnl ' + pClass + '">' + pStr + '</div>' +
|
|
'<div class="meta">' +
|
|
'<span>Trades: <span class="val">' + (s.trades_today || 0) + '</span></span>' +
|
|
'<span>Win: <span class="val">' + Math.round((s.win_rate || 0) * 100) + '%</span></span>' +
|
|
'<span>DD: <span class="val">' + ((s.max_drawdown || 0) * 100).toFixed(1) + '%</span></span>' +
|
|
'</div>' +
|
|
'</div>';
|
|
}
|
|
grid.innerHTML = cardsHtml;
|
|
|
|
// Equity chart
|
|
var history = data.equity_history || [];
|
|
if (history.length > 0) {
|
|
var labels = [];
|
|
var values = [];
|
|
for (var j = 0; j < history.length; j++) {
|
|
var ts = history[j].t * 1000;
|
|
labels.push(new Date(ts).toLocaleTimeString('en-US', { hour12: false }));
|
|
values.push(history[j].v);
|
|
}
|
|
|
|
equityChart.data.labels = labels;
|
|
equityChart.data.datasets[0].data = values;
|
|
equityChart.update('none');
|
|
}
|
|
|
|
// Trade log
|
|
var trades = (data.trades || []).slice(-15).reverse();
|
|
var tbody = document.getElementById('trade-body');
|
|
var rowsHtml = '';
|
|
for (var k = 0; k < trades.length; k++) {
|
|
var t = trades[k];
|
|
var tpnlClass = (t.pnl || 0) >= 0 ? 'pos' : 'neg';
|
|
var tpnlStr = ((t.pnl || 0) >= 0 ? '+' : '') + '$' + Math.abs(t.pnl || 0).toFixed(4);
|
|
var sideClass = t.side === 'BUY' ? 'buy' : 'sell';
|
|
rowsHtml += '<tr>' +
|
|
'<td>' + (t.time || '') + '</td>' +
|
|
'<td>' + (t.strategy || '') + '</td>' +
|
|
'<td class="' + sideClass + '">' + (t.side || '') + '</td>' +
|
|
'<td>' + (t.size || '') + '</td>' +
|
|
'<td class="' + tpnlClass + '">' + tpnlStr + '</td>' +
|
|
'</tr>';
|
|
}
|
|
tbody.innerHTML = rowsHtml;
|
|
}
|
|
|
|
// Start
|
|
connect();
|
|
</script>
|
|
</body>
|
|
</html>
|