From 2c6a239973b40f1b620ae690a1dbbf1b93ce35c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Sun, 18 Jan 2026 20:02:26 +0800 Subject: [PATCH] a --- frontend/src/components/StatsDashboard.jsx | 60 +++++++++++++++++----- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/StatsDashboard.jsx b/frontend/src/components/StatsDashboard.jsx index a25cb44..9d2f22c 100644 --- a/frontend/src/components/StatsDashboard.jsx +++ b/frontend/src/components/StatsDashboard.jsx @@ -250,12 +250,18 @@ const StatsDashboard = () => { } } - // 计算保证金(用于基于保证金的止损止盈) - const entryValue = trade.entry_value_usdt !== undefined - ? parseFloat(trade.entry_value_usdt) - : (quantity * entryPrice) + // 名义/保证金:优先使用后端返回字段(ATR接入后也用于统一口径) + const entryValue = trade.notional_usdt !== undefined && trade.notional_usdt !== null + ? parseFloat(trade.notional_usdt) + : ( + trade.entry_value_usdt !== undefined && trade.entry_value_usdt !== null + ? parseFloat(trade.entry_value_usdt) + : (quantity * entryPrice) + ) const leverage = parseFloat(trade.leverage || 10) - const margin = leverage > 0 ? entryValue / leverage : entryValue + const margin = trade.margin_usdt !== undefined && trade.margin_usdt !== null + ? parseFloat(trade.margin_usdt) + : (leverage > 0 ? entryValue / leverage : entryValue) // 从配置获取止损止盈比例(相对于保证金) const configSource = dashboardData?.trading_config || tradingConfig @@ -290,10 +296,6 @@ const StatsDashboard = () => { } } - // 计算止损止盈金额(相对于保证金) - const stopLossAmount = margin * stopLossPercentMargin - const takeProfitAmount = margin * takeProfitPercentMargin - // 计算止损价和止盈价(基于保证金金额) // 优先使用后端返回的止损止盈价格,如果没有则自己计算 let stopLossPrice = 0 @@ -304,6 +306,10 @@ const StatsDashboard = () => { stopLossPrice = parseFloat(trade.stop_loss_price) takeProfitPrice = parseFloat(trade.take_profit_price) } else { + // 计算止损止盈金额(相对于保证金) + const stopLossAmount = margin * stopLossPercentMargin + const takeProfitAmount = margin * takeProfitPercentMargin + // 自己计算止损止盈价格 // 止损金额 = (开仓价 - 止损价) × 数量 或 (止损价 - 开仓价) × 数量 if (side === 'BUY') { @@ -318,10 +324,24 @@ const StatsDashboard = () => { takeProfitPrice = entryPrice - (takeProfitAmount / quantity) } } - - // 计算止损比例和止盈比例(相对于保证金,用于显示) - const stopLossPercent = stopLossPercentMargin * 100 // 相对于保证金 - const takeProfitPercent = takeProfitPercentMargin * 100 // 相对于保证金 + + // ATR 接入后,止损/止盈“金额与比例”要以实际价格反推(否则会显示成配置值而非真实值) + let stopLossAmount = 0 + let takeProfitAmount = 0 + if (entryPrice > 0 && quantity > 0 && stopLossPrice > 0 && takeProfitPrice > 0) { + if (side === 'BUY') { + stopLossAmount = Math.max(0, (entryPrice - stopLossPrice) * quantity) + takeProfitAmount = Math.max(0, (takeProfitPrice - entryPrice) * quantity) + } else { + stopLossAmount = Math.max(0, (stopLossPrice - entryPrice) * quantity) + takeProfitAmount = Math.max(0, (entryPrice - takeProfitPrice) * quantity) + } + } else { + stopLossAmount = margin * stopLossPercentMargin + takeProfitAmount = margin * takeProfitPercentMargin + } + const stopLossPercent = margin > 0 ? (stopLossAmount / margin) * 100 : (stopLossPercentMargin * 100) + const takeProfitPercent = margin > 0 ? (takeProfitAmount / margin) * 100 : (takeProfitPercentMargin * 100) // 也计算价格百分比(用于参考) const stopLossPercentPrice = side === 'BUY' @@ -365,6 +385,7 @@ const StatsDashboard = () => {
数量: {parseFloat(trade.quantity || 0).toFixed(4)}
+
名义: {entryValue >= 0.01 ? entryValue.toFixed(2) : entryValue.toFixed(4)} USDT
保证金: {margin >= 0.01 ? margin.toFixed(2) : margin.toFixed(4)} USDT
入场价: {entryPrice.toFixed(4)}
@@ -374,6 +395,9 @@ const StatsDashboard = () => { {trade.leverage && (
杠杆: {trade.leverage}x
)} + {trade.atr !== undefined && trade.atr !== null && ( +
ATR: {parseFloat(trade.atr).toFixed(6)}
+ )} {/* 价格涨跌比例 */}
= 0 ? 'positive' : 'negative'}`}> @@ -400,6 +424,16 @@ const StatsDashboard = () => { (价: {takeProfitPrice.toFixed(4)}) (金额: +{takeProfitAmount >= 0.01 ? takeProfitAmount.toFixed(2) : takeProfitAmount.toFixed(4)} USDT)
+ {(trade.take_profit_1 || trade.take_profit_2) && ( +
+ {trade.take_profit_1 && ( + TP1: {parseFloat(trade.take_profit_1).toFixed(4)} + )} + {trade.take_profit_2 && ( + TP2: {parseFloat(trade.take_profit_2).toFixed(4)} + )} +
+ )}
= 0 ? 'positive' : 'negative'}`}>