diff --git a/decision/engine.go b/decision/engine.go index ed7989f5..15b4a892 100644 --- a/decision/engine.go +++ b/decision/engine.go @@ -37,6 +37,7 @@ type PositionInfo struct { Leverage int `json:"leverage"` UnrealizedPnL float64 `json:"unrealized_pnl"` UnrealizedPnLPct float64 `json:"unrealized_pnl_pct"` + PeakPnLPct float64 `json:"peak_pnl_pct"` // 历史最高收益率(百分比) LiquidationPrice float64 `json:"liquidation_price"` MarginUsed float64 `json:"margin_used"` UpdateTime int64 `json:"update_time"` // 持仓更新时间戳(毫秒) @@ -383,9 +384,9 @@ func buildUserPrompt(ctx *Context) string { } } - sb.WriteString(fmt.Sprintf("%d. %s %s | 入场价%.4f 当前价%.4f | 盈亏%+.2f%% | 杠杆%dx | 保证金%.0f | 强平价%.4f%s\n\n", + sb.WriteString(fmt.Sprintf("%d. %s %s | 入场价%.4f 当前价%.4f | 盈亏%+.2f%% | 盈亏金额%+.2f USDT | 最高收益率%.2f%% | 杠杆%dx | 保证金%.0f | 强平价%.4f%s\n\n", i+1, pos.Symbol, strings.ToUpper(pos.Side), - pos.EntryPrice, pos.MarkPrice, pos.UnrealizedPnLPct, + pos.EntryPrice, pos.MarkPrice, pos.UnrealizedPnLPct, pos.UnrealizedPnL, pos.PeakPnLPct, pos.Leverage, pos.MarginUsed, pos.LiquidationPrice, holdingDuration)) // 使用FormatMarketData输出完整市场数据 diff --git a/trader/auto_trader.go b/trader/auto_trader.go index 79879542..8eec4a42 100644 --- a/trader/auto_trader.go +++ b/trader/auto_trader.go @@ -647,6 +647,11 @@ func (at *AutoTrader) buildTradingContext() (*decision.Context, error) { } updateTime := at.positionFirstSeenTime[posKey] + // 获取该持仓的历史最高收益率 + at.peakPnLCacheMutex.RLock() + peakPnlPct := at.peakPnLCache[symbol] + at.peakPnLCacheMutex.RUnlock() + positionInfos = append(positionInfos, decision.PositionInfo{ Symbol: symbol, Side: side, @@ -656,6 +661,7 @@ func (at *AutoTrader) buildTradingContext() (*decision.Context, error) { Leverage: leverage, UnrealizedPnL: unrealizedPnl, UnrealizedPnLPct: pnlPct, + PeakPnLPct: peakPnlPct, LiquidationPrice: liquidationPrice, MarginUsed: marginUsed, UpdateTime: updateTime,