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 = () => {