Fix historical backtests tab not showing data
Root cause: switchTab() didn't show the historical panel (pnl-historical). Added panel visibility toggle and tab highlight for 'historical' tab. Also fixed broken JS quote escaping in loadHistBT function — ''+s+'' was missing backslash-escaped quotes, causing "Unexpected string" syntax error that prevented the entire script from executing. Historical tab now shows 7 real-data backtest cards from Hyperliquid mainnet candles.
This commit is contained in:
@@ -214,10 +214,11 @@ function initDetChart(){
|
|||||||
// ═══════════ Tab switching ═══════════
|
// ═══════════ Tab switching ═══════════
|
||||||
function switchTab(t){
|
function switchTab(t){
|
||||||
currentTab=t;
|
currentTab=t;
|
||||||
['live','paper','backtest'].forEach(function(x){document.getElementById('tl-'+x).className=t===x?'tab on':'tab'});
|
['live','paper','backtest','historical'].forEach(function(x){document.getElementById('tl-'+x).className=t===x?'tab on':'tab'});
|
||||||
document.getElementById('pnl-live').className=t==='live'?'panel show':'panel';
|
document.getElementById('pnl-live').className=t==='live'?'panel show':'panel';
|
||||||
document.getElementById('pnl-paper').className=t==='paper'?'panel show':'panel';
|
document.getElementById('pnl-paper').className=t==='paper'?'panel show':'panel';
|
||||||
document.getElementById('pnl-backtest').className=t==='backtest'?'panel show':'panel';
|
document.getElementById('pnl-backtest').className=t==='backtest'?'panel show':'panel';
|
||||||
|
document.getElementById('pnl-historical').className=t==='historical'?'panel show':'panel';
|
||||||
if(t==='live'&&lastData)renLive(lastData);
|
if(t==='live'&&lastData)renLive(lastData);
|
||||||
if(t==='paper'&&lastPaper)renPaper(lastPaper);
|
if(t==='paper'&&lastPaper)renPaper(lastPaper);
|
||||||
if(t==='backtest')loadBT();
|
if(t==='backtest')loadBT();
|
||||||
@@ -402,6 +403,35 @@ function loadBT(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ═══════════ Historical backtests ═══════════
|
||||||
|
var lastHist={};
|
||||||
|
function loadHistBT(){
|
||||||
|
fetch('/cv/api/backtests/historical').then(function(r){return r.json()}).then(function(data){
|
||||||
|
lastHist={};
|
||||||
|
for(var i=0;i<data.length;i++){var b=data[i];if(!lastHist[b.strategy])lastHist[b.strategy]=b;}
|
||||||
|
var h='';
|
||||||
|
for(var s in lastHist){var b=lastHist[s];var pnl=b.pnl_pct||0;
|
||||||
|
h+='<div class="scard" onclick="openHistDetail(\'+s+\')"><div class="sh"><div><div class="sname">'+s+'</div><div class="salloc">30d '+b.coin+' · Mainnet</div></div><span class="stag run">REAL DATA</span></div><div class="spnl '+(pnl>=0?'up':'dn')+'">'+(pnl>=0?'+':'')+pnl.toFixed(2)+'%</div><div class="smeta"><span>Sharpe: <b>'+b.sharpe.toFixed(2)+'</b></span><span>DD: <b class="red">'+(b.max_dd*100).toFixed(2)+'%</b></span><span>Win: <b>'+Math.round(b.win_rate*100)+'%</b></span></div></div>';
|
||||||
|
}
|
||||||
|
document.getElementById('hist-sgrid').innerHTML=h||'<div style="padding:20px;color:var(--tx)">No historical backtests. Run: python backtests/historical_runner.py --coin BTC --strategy all</div>';
|
||||||
|
})
|
||||||
|
}
|
||||||
|
function openHistDetail(strat){
|
||||||
|
var b=lastHist[strat];if(!b)return;
|
||||||
|
document.getElementById('detail-overlay').classList.add('on');
|
||||||
|
document.getElementById('fee-toggle-wrap').style.display='inline';
|
||||||
|
document.getElementById('fee-tier-sel').style.display='inline';
|
||||||
|
document.getElementById('stake-tier-sel').style.display='inline';
|
||||||
|
document.getElementById('dl-csv').style.display='none';
|
||||||
|
document.getElementById('fee-toggle').checked=true; feeOn=true; currentBTName=b.name;
|
||||||
|
document.getElementById('det-name').textContent=strat+' (Historical '+b.coin+')';
|
||||||
|
fetch('/cv/api/backtest/historical/'+encodeURIComponent(b.name)).then(function(r){return r.json()}).then(function(full){
|
||||||
|
lastBTFull=full; renderBTDetail(full);
|
||||||
|
}).catch(function(e){
|
||||||
|
document.getElementById('det-trades').innerHTML='<tr><td colspan="7" style="text-align:center;color:var(--rd);padding:20px">Failed: '+e.message+'</td></tr>';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════ Init ═══════════
|
// ═══════════ Init ═══════════
|
||||||
initDetChart();connect();loadBT();
|
initDetChart();connect();loadBT();
|
||||||
// ═══════════ Risk Analytics ═══════════
|
// ═══════════ Risk Analytics ═══════════
|
||||||
|
|||||||
Reference in New Issue
Block a user