From ee5dc614e0397404474f395a916c00d9a739589c Mon Sep 17 00:00:00 2001 From: dekun Date: Fri, 22 May 2026 17:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=98=BE=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto_monitor_binance/templates/index.html | 41 +++++++++++++++----- crypto_monitor_gate/templates/index.html | 41 +++++++++++++++----- crypto_monitor_gate_bot/templates/index.html | 31 ++++++++++++--- crypto_monitor_okx/templates/index.html | 31 ++++++++++++--- 4 files changed, 114 insertions(+), 30 deletions(-) diff --git a/crypto_monitor_binance/templates/index.html b/crypto_monitor_binance/templates/index.html index e9dc102..91032ad 100644 --- a/crypto_monitor_binance/templates/index.html +++ b/crypto_monitor_binance/templates/index.html @@ -433,9 +433,9 @@ data-monitor-id="{{ o.id }}" data-symbol="{{ o.symbol }}" data-direction="{{ o.direction }}" - data-plan-sl="{{ o.stop_loss or '' }}" - data-plan-tp="{{ o.take_profit or '' }}" - data-entry="{{ o.trigger_price or '' }}"> + data-plan-sl="{% if o.stop_loss %}{{ price_fmt(o.symbol, o.stop_loss) }}{% endif %}" + data-plan-tp="{% if o.take_profit %}{{ price_fmt(o.symbol, o.take_profit) }}{% endif %}" + data-entry="{% if o.trigger_price %}{{ price_fmt(o.symbol, o.trigger_price) }}{% endif %}">
{{ o.exchange_symbol or o.symbol }} @@ -924,9 +924,9 @@ function editTradeRecordReview(t){ if(opened === null) return; const closed = prompt("平仓时间(YYYY-MM-DD HH:MM:SS)", normalizeBeijingDatetimeString(t.closed_at || "")); if(closed === null) return; - const stopLoss = prompt("止损价格(核对后用于统计)", String(t.stop_loss ?? "")); + const stopLoss = prompt("止损价格(核对后用于统计)", formatPriceForInput(t.stop_loss)); if(stopLoss === null) return; - const takeProfit = prompt("止盈价格(核对后用于统计)", String(t.take_profit ?? "")); + const takeProfit = prompt("止盈价格(核对后用于统计)", formatPriceForInput(t.take_profit)); if(takeProfit === null) return; const pnl = prompt("最终盈亏(可手工核对后填写)", String(t.pnl_amount ?? "")); if(pnl === null) return; @@ -1174,6 +1174,24 @@ function coinFromSymbol(symbol){ return s; } +/** 输入框/备注用价格:去掉浮点尾数,按量级保留有效小数(与后端 price_fmt 兜底一致) */ +function formatPriceForInput(val){ + if(val === null || val === undefined || val === "") return ""; + const v = Number(val); + if(!Number.isFinite(v)) return String(val); + const av = Math.abs(v); + let d; + if(av >= 10000) d = 2; + else if(av >= 100) d = 3; + else if(av >= 1) d = 4; + else if(av >= 0.01) d = 6; + else if(av >= 0.0001) d = 8; + else d = 10; + let text = v.toFixed(d); + if(text.includes(".")) text = text.replace(/\.?0+$/, ""); + return text; +} + function calcExpectedRrFromTrade(t){ const entry = Number(t.trigger_price); const sl = Number(t.stop_loss); @@ -1212,10 +1230,13 @@ function fillJournalFromTrade(t){ setJournalField("real_rr", realRr); const riskHint = document.getElementById("risk-amount-hint"); if(riskHint){ riskHint.value = (Number.isFinite(riskAmount) && riskAmount > 0) ? String(riskAmount) : ""; } + const entryPx = formatPriceForInput(t.trigger_price); + const slPx = formatPriceForInput(t.stop_loss); + const tpPx = formatPriceForInput(t.take_profit); const entryHint = document.getElementById("entry-price-hint"); - if(entryHint){ entryHint.value = t.trigger_price || ""; } + if(entryHint){ entryHint.value = entryPx; } const stopHint = document.getElementById("stop-loss-hint"); - if(stopHint){ stopHint.value = t.stop_loss || ""; } + if(stopHint){ stopHint.value = slPx; } const dirHint = document.getElementById("direction-hint"); if(dirHint){ dirHint.value = t.direction || "long"; } setJournalField("early_exit_trigger", ""); @@ -1232,7 +1253,7 @@ function fillJournalFromTrade(t){ const er = String(t.result || "").trim(); const exitTrigMap = { 止盈: "止盈", 保本止盈: "保本止盈", 移动止盈: "移动止盈", 手动平仓: "手动平仓", 止损: "止损" }; if(exitTrigMap[er]) setJournalField("early_exit_trigger", exitTrigMap[er]); - const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${t.trigger_price || "-"} 止损:${t.stop_loss || "-"} 止盈:${t.take_profit || "-"} | 类型:${t.monitor_type || "-"}`; + const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${entryPx || "-"} 止损:${slPx || "-"} 止盈:${tpPx || "-"} | 类型:${t.monitor_type || "-"}`; setJournalField("note", note); const form = document.getElementById("journal-form"); if(form && typeof form.scrollIntoView === "function"){ @@ -1492,8 +1513,8 @@ function openTpslEntrustModal(orderId){ tpslEntrustMonitorId = orderId; const slEl = document.getElementById('tpsl-modal-sl'); const tpEl = document.getElementById('tpsl-modal-tp'); - if(slEl) slEl.value = card.getAttribute('data-plan-sl') || ''; - if(tpEl) tpEl.value = card.getAttribute('data-plan-tp') || ''; + if(slEl) slEl.value = formatPriceForInput(card.getAttribute('data-plan-sl') || ''); + if(tpEl) tpEl.value = formatPriceForInput(card.getAttribute('data-plan-tp') || ''); const modeEl = document.getElementById('tpsl-modal-mode'); if(modeEl) modeEl.value = 'price'; toggleTpslModalMode(); diff --git a/crypto_monitor_gate/templates/index.html b/crypto_monitor_gate/templates/index.html index e80ca5b..68fd217 100644 --- a/crypto_monitor_gate/templates/index.html +++ b/crypto_monitor_gate/templates/index.html @@ -433,9 +433,9 @@ data-monitor-id="{{ o.id }}" data-symbol="{{ o.symbol }}" data-direction="{{ o.direction }}" - data-plan-sl="{{ o.stop_loss or '' }}" - data-plan-tp="{{ o.take_profit or '' }}" - data-entry="{{ o.trigger_price or '' }}"> + data-plan-sl="{% if o.stop_loss %}{{ price_fmt(o.symbol, o.stop_loss) }}{% endif %}" + data-plan-tp="{% if o.take_profit %}{{ price_fmt(o.symbol, o.take_profit) }}{% endif %}" + data-entry="{% if o.trigger_price %}{{ price_fmt(o.symbol, o.trigger_price) }}{% endif %}">
{{ o.exchange_symbol or o.symbol }} @@ -934,9 +934,9 @@ function editTradeRecordReview(t){ if(opened === null) return; const closed = prompt("平仓时间(YYYY-MM-DD HH:MM:SS)", normalizeBeijingDatetimeString(t.closed_at || "")); if(closed === null) return; - const stopLoss = prompt("止损价格(核对后用于统计)", String(t.stop_loss ?? "")); + const stopLoss = prompt("止损价格(核对后用于统计)", formatPriceForInput(t.stop_loss)); if(stopLoss === null) return; - const takeProfit = prompt("止盈价格(核对后用于统计)", String(t.take_profit ?? "")); + const takeProfit = prompt("止盈价格(核对后用于统计)", formatPriceForInput(t.take_profit)); if(takeProfit === null) return; const pnl = prompt("最终盈亏(可手工核对后填写)", (t.pnl_amount === null || typeof t.pnl_amount === "undefined") ? "" : (Number.isFinite(Number(t.pnl_amount)) ? Number(t.pnl_amount).toFixed(2) : String(t.pnl_amount))); if(pnl === null) return; @@ -1184,6 +1184,24 @@ function coinFromSymbol(symbol){ return s; } +/** 输入框/备注用价格:去掉浮点尾数,按量级保留有效小数(与后端 price_fmt 兜底一致) */ +function formatPriceForInput(val){ + if(val === null || val === undefined || val === "") return ""; + const v = Number(val); + if(!Number.isFinite(v)) return String(val); + const av = Math.abs(v); + let d; + if(av >= 10000) d = 2; + else if(av >= 100) d = 3; + else if(av >= 1) d = 4; + else if(av >= 0.01) d = 6; + else if(av >= 0.0001) d = 8; + else d = 10; + let text = v.toFixed(d); + if(text.includes(".")) text = text.replace(/\.?0+$/, ""); + return text; +} + function calcExpectedRrFromTrade(t){ const entry = Number(t.trigger_price); const sl = Number(t.stop_loss); @@ -1222,10 +1240,13 @@ function fillJournalFromTrade(t){ setJournalField("real_rr", realRr); const riskHint = document.getElementById("risk-amount-hint"); if(riskHint){ riskHint.value = (Number.isFinite(riskAmount) && riskAmount > 0) ? riskAmount.toFixed(2) : ""; } + const entryPx = formatPriceForInput(t.trigger_price); + const slPx = formatPriceForInput(t.stop_loss); + const tpPx = formatPriceForInput(t.take_profit); const entryHint = document.getElementById("entry-price-hint"); - if(entryHint){ entryHint.value = t.trigger_price || ""; } + if(entryHint){ entryHint.value = entryPx; } const stopHint = document.getElementById("stop-loss-hint"); - if(stopHint){ stopHint.value = t.stop_loss || ""; } + if(stopHint){ stopHint.value = slPx; } const dirHint = document.getElementById("direction-hint"); if(dirHint){ dirHint.value = t.direction || "long"; } setJournalField("early_exit_trigger", ""); @@ -1242,7 +1263,7 @@ function fillJournalFromTrade(t){ const er = String(t.result || "").trim(); const exitTrigMap = { 止盈: "止盈", 保本止盈: "保本止盈", 移动止盈: "移动止盈", 手动平仓: "手动平仓", 止损: "止损" }; if(exitTrigMap[er]) setJournalField("early_exit_trigger", exitTrigMap[er]); - const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${t.trigger_price || "-"} 止损:${t.stop_loss || "-"} 止盈:${t.take_profit || "-"} | 类型:${t.monitor_type || "-"}`; + const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${entryPx || "-"} 止损:${slPx || "-"} 止盈:${tpPx || "-"} | 类型:${t.monitor_type || "-"}`; setJournalField("note", note); const form = document.getElementById("journal-form"); if(form && typeof form.scrollIntoView === "function"){ @@ -1502,8 +1523,8 @@ function openTpslEntrustModal(orderId){ tpslEntrustMonitorId = orderId; const slEl = document.getElementById('tpsl-modal-sl'); const tpEl = document.getElementById('tpsl-modal-tp'); - if(slEl) slEl.value = card.getAttribute('data-plan-sl') || ''; - if(tpEl) tpEl.value = card.getAttribute('data-plan-tp') || ''; + if(slEl) slEl.value = formatPriceForInput(card.getAttribute('data-plan-sl') || ''); + if(tpEl) tpEl.value = formatPriceForInput(card.getAttribute('data-plan-tp') || ''); const modeEl = document.getElementById('tpsl-modal-mode'); if(modeEl) modeEl.value = 'price'; toggleTpslModalMode(); diff --git a/crypto_monitor_gate_bot/templates/index.html b/crypto_monitor_gate_bot/templates/index.html index a027b12..6c24e13 100644 --- a/crypto_monitor_gate_bot/templates/index.html +++ b/crypto_monitor_gate_bot/templates/index.html @@ -981,9 +981,9 @@ function editTradeRecordReview(t){ if(opened === null) return; const closed = prompt("平仓时间(YYYY-MM-DD HH:MM:SS)", normalizeBeijingDatetimeString(t.closed_at || "")); if(closed === null) return; - const stopLoss = prompt("止损价格(核对后用于统计)", String(t.stop_loss ?? "")); + const stopLoss = prompt("止损价格(核对后用于统计)", formatPriceForInput(t.stop_loss)); if(stopLoss === null) return; - const takeProfit = prompt("止盈价格(核对后用于统计)", String(t.take_profit ?? "")); + const takeProfit = prompt("止盈价格(核对后用于统计)", formatPriceForInput(t.take_profit)); if(takeProfit === null) return; const pnl = prompt("最终盈亏(可手工核对后填写)", String(t.pnl_amount ?? "")); if(pnl === null) return; @@ -1184,6 +1184,24 @@ function coinFromSymbol(symbol){ return s; } +/** 输入框/备注用价格:去掉浮点尾数,按量级保留有效小数(与后端 price_fmt 兜底一致) */ +function formatPriceForInput(val){ + if(val === null || val === undefined || val === "") return ""; + const v = Number(val); + if(!Number.isFinite(v)) return String(val); + const av = Math.abs(v); + let d; + if(av >= 10000) d = 2; + else if(av >= 100) d = 3; + else if(av >= 1) d = 4; + else if(av >= 0.01) d = 6; + else if(av >= 0.0001) d = 8; + else d = 10; + let text = v.toFixed(d); + if(text.includes(".")) text = text.replace(/\.?0+$/, ""); + return text; +} + function calcExpectedRrFromTrade(t){ const entry = Number(t.trigger_price); const sl = Number(t.stop_loss); @@ -1222,10 +1240,13 @@ function fillJournalFromTrade(t){ setJournalField("real_rr", realRr); const riskHint = document.getElementById("risk-amount-hint"); if(riskHint){ riskHint.value = (Number.isFinite(riskAmount) && riskAmount > 0) ? String(riskAmount) : ""; } + const entryPx = formatPriceForInput(t.trigger_price); + const slPx = formatPriceForInput(t.stop_loss); + const tpPx = formatPriceForInput(t.take_profit); const entryHint = document.getElementById("entry-price-hint"); - if(entryHint){ entryHint.value = t.trigger_price || ""; } + if(entryHint){ entryHint.value = entryPx; } const stopHint = document.getElementById("stop-loss-hint"); - if(stopHint){ stopHint.value = t.stop_loss || ""; } + if(stopHint){ stopHint.value = slPx; } const dirHint = document.getElementById("direction-hint"); if(dirHint){ dirHint.value = t.direction || "long"; } setJournalField("early_exit_trigger", ""); @@ -1240,7 +1261,7 @@ function fillJournalFromTrade(t){ const er = String(t.result || "").trim(); const exitTrigMap = { 保本止盈: "保本止盈", 移动止盈: "移动止盈", 手动平仓: "手动平仓", 止损: "止损" }; if(exitTrigMap[er]) setJournalField("early_exit_trigger", exitTrigMap[er]); - const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${t.trigger_price || "-"} 止损:${t.stop_loss || "-"} 止盈:${t.take_profit || "-"} | 类型:${t.monitor_type || "-"}`; + const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${entryPx || "-"} 止损:${slPx || "-"} 止盈:${tpPx || "-"} | 类型:${t.monitor_type || "-"}`; setJournalField("note", note); const form = document.getElementById("journal-form"); if(form && typeof form.scrollIntoView === "function"){ diff --git a/crypto_monitor_okx/templates/index.html b/crypto_monitor_okx/templates/index.html index fcbb804..3f971cf 100644 --- a/crypto_monitor_okx/templates/index.html +++ b/crypto_monitor_okx/templates/index.html @@ -798,9 +798,9 @@ function editTradeRecordReview(t){ if(opened === null) return; const closed = prompt("平仓时间(YYYY-MM-DD HH:MM:SS)", normalizeBeijingDatetimeString(t.closed_at || "")); if(closed === null) return; - const stopLoss = prompt("止损价格(核对后用于统计)", String(t.stop_loss ?? "")); + const stopLoss = prompt("止损价格(核对后用于统计)", formatPriceForInput(t.stop_loss)); if(stopLoss === null) return; - const takeProfit = prompt("止盈价格(核对后用于统计)", String(t.take_profit ?? "")); + const takeProfit = prompt("止盈价格(核对后用于统计)", formatPriceForInput(t.take_profit)); if(takeProfit === null) return; const pnl = prompt("最终盈亏(可手工核对后填写)", String(t.pnl_amount ?? "")); if(pnl === null) return; @@ -1007,6 +1007,24 @@ function coinFromSymbol(symbol){ return s; } +/** 输入框/备注用价格:去掉浮点尾数,按量级保留有效小数(与后端 price_fmt 兜底一致) */ +function formatPriceForInput(val){ + if(val === null || val === undefined || val === "") return ""; + const v = Number(val); + if(!Number.isFinite(v)) return String(val); + const av = Math.abs(v); + let d; + if(av >= 10000) d = 2; + else if(av >= 100) d = 3; + else if(av >= 1) d = 4; + else if(av >= 0.01) d = 6; + else if(av >= 0.0001) d = 8; + else d = 10; + let text = v.toFixed(d); + if(text.includes(".")) text = text.replace(/\.?0+$/, ""); + return text; +} + function calcExpectedRrFromTrade(t){ const entry = Number(t.trigger_price); const sl = Number(t.stop_loss); @@ -1045,10 +1063,13 @@ function fillJournalFromTrade(t){ setJournalField("real_rr", realRr); const riskHint = document.getElementById("risk-amount-hint"); if(riskHint){ riskHint.value = (Number.isFinite(riskAmount) && riskAmount > 0) ? String(riskAmount) : ""; } + const entryPx = formatPriceForInput(t.trigger_price); + const slPx = formatPriceForInput(t.stop_loss); + const tpPx = formatPriceForInput(t.take_profit); const entryHint = document.getElementById("entry-price-hint"); - if(entryHint){ entryHint.value = t.trigger_price || ""; } + if(entryHint){ entryHint.value = entryPx; } const stopHint = document.getElementById("stop-loss-hint"); - if(stopHint){ stopHint.value = t.stop_loss || ""; } + if(stopHint){ stopHint.value = slPx; } const dirHint = document.getElementById("direction-hint"); if(dirHint){ dirHint.value = t.direction || "long"; } setJournalField("early_exit_trigger", ""); @@ -1065,7 +1086,7 @@ function fillJournalFromTrade(t){ const er = String(t.result || "").trim(); const exitTrigMap = { 止盈: "止盈", 保本止盈: "保本止盈", 移动止盈: "移动止盈", 手动平仓: "手动平仓", 止损: "止损" }; if(exitTrigMap[er]) setJournalField("early_exit_trigger", exitTrigMap[er]); - const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${t.trigger_price || "-"} 止损:${t.stop_loss || "-"} 止盈:${t.take_profit || "-"} | 类型:${t.monitor_type || "-"}`; + const note = `来自交易记录自动填充:${t.symbol || "-"} ${t.direction || "-"} | 入场:${entryPx || "-"} 止损:${slPx || "-"} 止盈:${tpPx || "-"} | 类型:${t.monitor_type || "-"}`; setJournalField("note", note); const form = document.getElementById("journal-form"); if(form && typeof form.scrollIntoView === "function"){