@@ -92,7 +92,8 @@ const chartEl=document.getElementById('chart');const chart=LightweightCharts.cre
function $(id){return document.getElementById(id)} function esc(s){return String(s??'').replace(/[&<>'"]/g,c=>({'&':'&','<':'<','>':'>',"'":''','"':'"'}[c]))} function getMarket(){return $('marketSelect').value||'BTCUSDT'} function actionRu(a){return{buy:'Покупать',sell:'Продавать',hold:'Ждать'}[a]||a||'—'}
function showTab(id,btn){document.querySelectorAll('.section').forEach(x=>x.classList.remove('active'));$(id).classList.add('active');document.querySelectorAll('.nav button').forEach(x=>x.classList.remove('active'));btn.classList.add('active');if(id==='trade')loadTrades();if(['strategies','coinex','limits'].includes(id))loadLegacy();setTimeout(()=>chart.applyOptions({width:chartEl.clientWidth,height:chartEl.clientHeight||610}),50)}
function renderDecision(obj){const d=obj.decision||obj,ind=d.indicators||obj.indicators||{};$('aiResult').innerHTML=`
`}
function renderMonitor(m){if(!m)return;$('monitorLabel').textContent=m.running?'ON':'OFF';$('monitorLabel').style.color=m.running?'var(--good)':'var(--bad)';$('monitorBox').innerHTML=`
Статус${esc(m.status||'—')}
Последняя пара${esc(m.last_market||'—')}
Действие${esc(actionRu(m.last_action))}
Оценка${Number(m.last_score||0).toFixed(1)}
${m.last_error?`
Ошибка: ${esc(m.last_error)}
`:''}`}
function renderKpi(k){$('pnl').textContent=Number(k.realized_pnl||0).toFixed(2)+' USDT';$('openTrades').textContent=k.open_positions??0}
async function bootstrap(){const r=await fetch('/api/v1/app/bootstrap');const j=await r.json();$('marketSelect').innerHTML='';(j.markets||['BTCUSDT']).forEach(m=>{const o=document.createElement('option');o.value=m;o.textContent=m;if(m===j.default_market)o.selected=true;$('marketSelect').appendChild(o)});renderAccount(j.account);renderSettings(j.bot);renderMonitor(j.monitor);if(j.legacy)renderLegacy(j.legacy);await loadSelectedMarket();setInterval(refreshMonitor,5000);setInterval(loadLegacy,8000)}
@@ -101,7 +102,7 @@ function normalizeKline(raw){const rows=raw.data||[];const c=rows.map(r=>({time:
function updateLiveCandle(p,t){if(!Number.isFinite(p))return;const b=Math.floor((t||Date.now())/60000)*60;if(!currentCandle||currentCandle.time!==b)currentCandle={time:b,open:p,high:p,low:p,close:p};else{currentCandle.high=Math.max(currentCandle.high,p);currentCandle.low=Math.min(currentCandle.low,p);currentCandle.close=p}candleSeries.update(currentCandle)}
async function loadSelectedMarket(){const m=getMarket();$('status').textContent='загрузка...';const r=await fetch(`/api/v1/market/kline?market=${m}&period=1min&limit=200`);candleSeries.setData(normalizeKline(await r.json()));chart.timeScale().fitContent();await loadMarkers(m);connectWs(m);await loadAccount();await loadLegacy()}
async function loadAccount(){const r=await fetch('/api/v1/demo/account');renderAccount(await r.json())} async function loadMarkers(m){const r=await fetch(`/api/v1/dashboard/markers?market=${m}&limit=100`);const j=await r.json();candleSeries.setMarkers((j.items||[]).map(i=>({time:i.time,position:i.side==='buy'?'belowBar':'aboveBar',shape:i.side==='buy'?'arrowUp':'arrowDown',text:i.text})))}
-async function autoPickMarket(){$('status').textContent='AI выбирает пару...';const r=await fetch('/api/v1/bot/best-market');const j=await r.json();if(j.market){$('marketSelect').value=j.market;renderDecision(j);await loadSelectedMarket()}else renderDecision(j)} async function analyze(){const r=await fetch(`/api/v1/bot/analyze?market=${getMarket()}`);renderDecision(await r.json())} async function decide(){const r=await fetch(`/api/v1/bot/decide?market=${getMarket()}`,{method:'POST'});renderDecision(await r.json())} async function autoTrade(){const r=await fetch(`/api/v1/bot/auto-trade?market=${getMarket()}`,{method:'POST'});renderDecision(await r.json());await loadAccount();await loadMarkers(getMarket());await loadLegacy()} async function setMode(mode){const r=await fetch(`/api/v1/bot/settings?trade_mode=${mode}`,{method:'POST'});renderSettings(await r.json())}
+async function autoPickMarket(){$('status').textContent='AI выбирает пару...';const r=await fetch('/api/v1/bot/best-market');const j=await r.json();if(j.market){$('marketSelect').value=j.market;renderDecision(j);await loadSelectedMarket()}else renderDecision(j)} async function analyze(){const r=await fetch(`/api/v1/bot/analyze?market=${getMarket()}`);renderDecision(await r.json())} async function decide(){const r=await fetch(`/api/v1/bot/decide?market=${getMarket()}`,{method:'POST'});renderDecision(await r.json())} async function autoTrade(){const r=await fetch(`/api/v1/bot/auto-trade?market=${getMarket()}`,{method:'POST'});renderDecision(await r.json());await loadAccount();await loadMarkers(getMarket());await loadLegacy()} async function toggleLiveMode(isLive){const r=await fetch(`/api/v1/bot/settings?trade_mode=${isLive?'live':'demo'}`,{method:'POST'});renderSettings(await r.json())}
async function saveLimits(){const q=`max_quote_per_trade=${encodeURIComponent($('limitAmount').value)}&min_signal_score=${encodeURIComponent($('limitScore').value)}&max_open_positions=${encodeURIComponent($('limitPositions').value)}`;const r=await fetch(`/api/v1/bot/settings?${q}`,{method:'POST'});renderSettings(await r.json())}
async function startMonitor(){const r=await fetch('/api/v1/monitor/start',{method:'POST'});const j=await r.json();renderMonitor(j);if(j.bot)renderSettings(j.bot)} async function stopMonitor(){const r=await fetch('/api/v1/monitor/stop',{method:'POST'});const j=await r.json();renderMonitor(j);if(j.bot)renderSettings(j.bot)} async function refreshMonitor(){const r=await fetch('/api/v1/monitor/status');renderMonitor(await r.json())}
async function loadLegacy(){const r=await fetch('/api/v1/legacy/dashboard');renderLegacy(await r.json());loadTrades()} function renderLegacy(j){renderKpi(j.kpi||{});$('strategyTable').innerHTML=(j.strategies||[]).map(s=>`