diff --git a/manual_trading_hub/static/archive.js b/manual_trading_hub/static/archive.js index 68cce59..d6807ab 100644 --- a/manual_trading_hub/static/archive.js +++ b/manual_trading_hub/static/archive.js @@ -58,7 +58,7 @@ let tradingDay = ""; let selected = null; let trades = []; - let selectedTradeId = null; + let selectedTradeKey = null; let timeframe = "15m"; let chart = null; let candleSeries = null; @@ -229,6 +229,23 @@ return exKey ? exchangeLabel(exKey) : "—"; } + function tradeRowKey(tr) { + if (!tr) return ""; + const exKey = String(tr.exchange_key || "").toLowerCase(); + const tid = tr.trade_id != null ? tr.trade_id : tr.id; + if (!exKey || tid == null || tid === "") return ""; + return exKey + ":" + String(tid); + } + + function findTradeByKey(key) { + if (!key) return null; + return ( + dailyTrades.find(function (t) { + return tradeRowKey(t) === String(key); + }) || null + ); + } + function applyTagSelectStyle(sel) { if (!sel) return; const v = sel.value || ""; @@ -272,7 +289,7 @@ }); if (!tr) return; selected = { exchange_key: tr.exchange_key, symbol: tr.symbol }; - selectedTradeId = String(tr.trade_id || tr.id); + selectedTradeKey = tradeRowKey(tr); await loadSymbolTradesForChart(tr.exchange_key, tr.symbol); } @@ -589,9 +606,9 @@ function pickAnchorTrade() { if (!trades.length) return null; - if (selectedTradeId != null) { + if (selectedTradeKey) { const hit = trades.find(function (t) { - return String(t.trade_id || t.id) === String(selectedTradeId); + return tradeRowKey(t) === selectedTradeKey; }); if (hit) return hit; } @@ -721,10 +738,10 @@ const multi = sorted.length > 1; const out = []; sorted.forEach(function (row, idx) { - const tid = String(row.trade_id || row.id); + const rowKey = tradeRowKey(row); const parts = buildTradeMarkers(row, candles, tf, { labelSuffix: multi ? String(idx + 1) : "", - highlight: tid === String(selectedTradeId), + highlight: rowKey === selectedTradeKey, }); out.push.apply(out, parts); }); @@ -937,7 +954,7 @@ return; } selected = { exchange_key: exKey, symbol: sym }; - selectedTradeId = String(tr.trade_id || tr.id); + selectedTradeKey = tradeRowKey(tr); renderTrades(); setChartOpen(true); await loadSymbolTradesForChart(exKey, sym); @@ -960,14 +977,17 @@ .map(function (t) { const tid = t.trade_id || t.id; const exKey = String(t.exchange_key || "").toLowerCase(); + const rowKey = tradeRowKey(t); const tag = t.behavior_tag || ""; const sick = tag === "sick"; - const active = String(tid) === String(selectedTradeId) ? " is-active" : ""; + const active = rowKey && rowKey === selectedTradeKey ? " is-active" : ""; const rev = reviewMark(t); return ( ' - +