From fd3fc654cbcc45bb2288af494de6f0ccd0be8615 Mon Sep 17 00:00:00 2001 From: Lawrence Liu Date: Sun, 9 Nov 2025 16:20:52 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20=E5=8E=86=E5=8F=B2=E6=9C=80=E9=AB=98?= =?UTF-8?q?=E6=94=B6=E7=9B=8A=E7=8E=87=EF=BC=88=E7=99=BE=E5=88=86=E6=AF=94?= =?UTF-8?q?=EF=BC=89,=20=E7=9B=88=E4=BA=8F=E9=87=91=E9=A2=9D=20USDT,=20?= =?UTF-8?q?=E6=9C=80=E9=AB=98=E6=94=B6=E7=9B=8A=E7=8E=87=20=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E4=BC=A0=E9=80=92=E7=BB=99=20AI=20=E4=BD=9C=E5=86=B3?= =?UTF-8?q?=E7=AD=96=EF=BC=8C=E6=97=A0=E6=B3=95=E5=9C=A8=20prompt=20?= =?UTF-8?q?=E4=B8=AD=E4=BD=BF=E7=94=A8=20(#651)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decision/engine.go | 5 +++-- trader/auto_trader.go | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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,