From beb9561742cc51326580f431001165ccdfd4c983 Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Thu, 30 Oct 2025 18:09:16 +0800 Subject: [PATCH] =?UTF-8?q?Feature:=20Add=20position=20details=20to=20Trad?= =?UTF-8?q?e=20History=20Add=20missing=20fields=20to=20TradeOutcome:=20-?= =?UTF-8?q?=20Quantity:=20Position=20size=20-=20Leverage:=20Leverage=20mul?= =?UTF-8?q?tiplier=20-=20PositionValue:=20Total=20position=20value=20(quan?= =?UTF-8?q?tity=20=C3=97=20openPrice)=20-=20MarginUsed:=20Margin=20require?= =?UTF-8?q?d=20(positionValue=20/=20leverage)=20This=20provides=20complete?= =?UTF-8?q?=20trade=20information=20for=20analysis=20and=20display.=20Co-A?= =?UTF-8?q?uthored-By:=20tinkle-community=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logger/decision_logger.go | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/logger/decision_logger.go b/logger/decision_logger.go index 0338e1e2..ed446f20 100644 --- a/logger/decision_logger.go +++ b/logger/decision_logger.go @@ -269,16 +269,20 @@ type Statistics struct { // TradeOutcome 单笔交易结果 type TradeOutcome struct { - Symbol string `json:"symbol"` // 币种 - Side string `json:"side"` // long/short - OpenPrice float64 `json:"open_price"` // 开仓价 - ClosePrice float64 `json:"close_price"` // 平仓价 - PnL float64 `json:"pn_l"` // 盈亏(USDT) - PnLPct float64 `json:"pn_l_pct"` // 盈亏百分比 - Duration string `json:"duration"` // 持仓时长 - OpenTime time.Time `json:"open_time"` // 开仓时间 - CloseTime time.Time `json:"close_time"` // 平仓时间 - WasStopLoss bool `json:"was_stop_loss"` // 是否止损 + Symbol string `json:"symbol"` // 币种 + Side string `json:"side"` // long/short + Quantity float64 `json:"quantity"` // 仓位数量 + Leverage int `json:"leverage"` // 杠杆倍数 + OpenPrice float64 `json:"open_price"` // 开仓价 + ClosePrice float64 `json:"close_price"` // 平仓价 + PositionValue float64 `json:"position_value"` // 仓位价值(quantity × openPrice) + MarginUsed float64 `json:"margin_used"` // 保证金使用(positionValue / leverage) + PnL float64 `json:"pn_l"` // 盈亏(USDT) + PnLPct float64 `json:"pn_l_pct"` // 盈亏百分比(相对保证金) + Duration string `json:"duration"` // 持仓时长 + OpenTime time.Time `json:"open_time"` // 开仓时间 + CloseTime time.Time `json:"close_time"` // 平仓时间 + WasStopLoss bool `json:"was_stop_loss"` // 是否止损 } // PerformanceAnalysis 交易表现分析 @@ -424,15 +428,19 @@ func (l *DecisionLogger) AnalyzePerformance(lookbackCycles int) (*PerformanceAna // 记录交易结果 outcome := TradeOutcome{ - Symbol: symbol, - Side: side, - OpenPrice: openPrice, - ClosePrice: action.Price, - PnL: pnl, - PnLPct: pnlPct, - Duration: action.Timestamp.Sub(openTime).String(), - OpenTime: openTime, - CloseTime: action.Timestamp, + Symbol: symbol, + Side: side, + Quantity: quantity, + Leverage: leverage, + OpenPrice: openPrice, + ClosePrice: action.Price, + PositionValue: positionValue, + MarginUsed: marginUsed, + PnL: pnl, + PnLPct: pnlPct, + Duration: action.Timestamp.Sub(openTime).String(), + OpenTime: openTime, + CloseTime: action.Timestamp, } analysis.RecentTrades = append(analysis.RecentTrades, outcome)