a
This commit is contained in:
parent
69145c4345
commit
2c6a239973
|
|
@ -250,12 +250,18 @@ const StatsDashboard = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算保证金(用于基于保证金的止损止盈)
|
// 名义/保证金:优先使用后端返回字段(ATR接入后也用于统一口径)
|
||||||
const entryValue = trade.entry_value_usdt !== undefined
|
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)
|
? parseFloat(trade.entry_value_usdt)
|
||||||
: (quantity * entryPrice)
|
: (quantity * entryPrice)
|
||||||
|
)
|
||||||
const leverage = parseFloat(trade.leverage || 10)
|
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
|
const configSource = dashboardData?.trading_config || tradingConfig
|
||||||
|
|
@ -290,10 +296,6 @@ const StatsDashboard = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算止损止盈金额(相对于保证金)
|
|
||||||
const stopLossAmount = margin * stopLossPercentMargin
|
|
||||||
const takeProfitAmount = margin * takeProfitPercentMargin
|
|
||||||
|
|
||||||
// 计算止损价和止盈价(基于保证金金额)
|
// 计算止损价和止盈价(基于保证金金额)
|
||||||
// 优先使用后端返回的止损止盈价格,如果没有则自己计算
|
// 优先使用后端返回的止损止盈价格,如果没有则自己计算
|
||||||
let stopLossPrice = 0
|
let stopLossPrice = 0
|
||||||
|
|
@ -304,6 +306,10 @@ const StatsDashboard = () => {
|
||||||
stopLossPrice = parseFloat(trade.stop_loss_price)
|
stopLossPrice = parseFloat(trade.stop_loss_price)
|
||||||
takeProfitPrice = parseFloat(trade.take_profit_price)
|
takeProfitPrice = parseFloat(trade.take_profit_price)
|
||||||
} else {
|
} else {
|
||||||
|
// 计算止损止盈金额(相对于保证金)
|
||||||
|
const stopLossAmount = margin * stopLossPercentMargin
|
||||||
|
const takeProfitAmount = margin * takeProfitPercentMargin
|
||||||
|
|
||||||
// 自己计算止损止盈价格
|
// 自己计算止损止盈价格
|
||||||
// 止损金额 = (开仓价 - 止损价) × 数量 或 (止损价 - 开仓价) × 数量
|
// 止损金额 = (开仓价 - 止损价) × 数量 或 (止损价 - 开仓价) × 数量
|
||||||
if (side === 'BUY') {
|
if (side === 'BUY') {
|
||||||
|
|
@ -319,9 +325,23 @@ const StatsDashboard = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算止损比例和止盈比例(相对于保证金,用于显示)
|
// ATR 接入后,止损/止盈“金额与比例”要以实际价格反推(否则会显示成配置值而非真实值)
|
||||||
const stopLossPercent = stopLossPercentMargin * 100 // 相对于保证金
|
let stopLossAmount = 0
|
||||||
const takeProfitPercent = takeProfitPercentMargin * 100 // 相对于保证金
|
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'
|
const stopLossPercentPrice = side === 'BUY'
|
||||||
|
|
@ -365,6 +385,7 @@ const StatsDashboard = () => {
|
||||||
</div>
|
</div>
|
||||||
<div className="trade-info">
|
<div className="trade-info">
|
||||||
<div>数量: {parseFloat(trade.quantity || 0).toFixed(4)}</div>
|
<div>数量: {parseFloat(trade.quantity || 0).toFixed(4)}</div>
|
||||||
|
<div>名义: {entryValue >= 0.01 ? entryValue.toFixed(2) : entryValue.toFixed(4)} USDT</div>
|
||||||
<div>保证金: {margin >= 0.01 ? margin.toFixed(2) : margin.toFixed(4)} USDT</div>
|
<div>保证金: {margin >= 0.01 ? margin.toFixed(2) : margin.toFixed(4)} USDT</div>
|
||||||
|
|
||||||
<div>入场价: {entryPrice.toFixed(4)}</div>
|
<div>入场价: {entryPrice.toFixed(4)}</div>
|
||||||
|
|
@ -374,6 +395,9 @@ const StatsDashboard = () => {
|
||||||
{trade.leverage && (
|
{trade.leverage && (
|
||||||
<div>杠杆: {trade.leverage}x</div>
|
<div>杠杆: {trade.leverage}x</div>
|
||||||
)}
|
)}
|
||||||
|
{trade.atr !== undefined && trade.atr !== null && (
|
||||||
|
<div>ATR: {parseFloat(trade.atr).toFixed(6)}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 价格涨跌比例 */}
|
{/* 价格涨跌比例 */}
|
||||||
<div className={`price-change ${priceChangePercent >= 0 ? 'positive' : 'negative'}`}>
|
<div className={`price-change ${priceChangePercent >= 0 ? 'positive' : 'negative'}`}>
|
||||||
|
|
@ -400,6 +424,16 @@ const StatsDashboard = () => {
|
||||||
<span className="take-price">(价: {takeProfitPrice.toFixed(4)})</span>
|
<span className="take-price">(价: {takeProfitPrice.toFixed(4)})</span>
|
||||||
<span className="take-amount">(金额: +{takeProfitAmount >= 0.01 ? takeProfitAmount.toFixed(2) : takeProfitAmount.toFixed(4)} USDT)</span>
|
<span className="take-amount">(金额: +{takeProfitAmount >= 0.01 ? takeProfitAmount.toFixed(2) : takeProfitAmount.toFixed(4)} USDT)</span>
|
||||||
</div>
|
</div>
|
||||||
|
{(trade.take_profit_1 || trade.take_profit_2) && (
|
||||||
|
<div style={{ marginTop: '6px', fontSize: '12px', color: '#666' }}>
|
||||||
|
{trade.take_profit_1 && (
|
||||||
|
<span style={{ marginRight: '10px' }}>TP1: {parseFloat(trade.take_profit_1).toFixed(4)}</span>
|
||||||
|
)}
|
||||||
|
{trade.take_profit_2 && (
|
||||||
|
<span>TP2: {parseFloat(trade.take_profit_2).toFixed(4)}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="trade-actions">
|
<div className="trade-actions">
|
||||||
<div className={`trade-pnl ${parseFloat(trade.pnl || 0) >= 0 ? 'positive' : 'negative'}`}>
|
<div className={`trade-pnl ${parseFloat(trade.pnl || 0) >= 0 ? 'positive' : 'negative'}`}>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user