Fix 历史最高收益率(百分比), 盈亏金额 USDT, 最高收益率 没有传递给 AI 作决策,无法在 prompt 中使用 (#651)

This commit is contained in:
Lawrence Liu
2025-11-09 16:20:52 +08:00
committed by GitHub
parent 576dd26b8b
commit fd3fc654cb
2 changed files with 9 additions and 2 deletions

View File

@@ -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输出完整市场数据

View File

@@ -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,