============================================================================ Prompt Building - User Prompt ============================================================================ BuildUserPrompt builds User Prompt based on strategy configuration
(ctx *Context)
| 717 | |
| 718 | // BuildUserPrompt builds User Prompt based on strategy configuration |
| 719 | func (e *StrategyEngine) BuildUserPrompt(ctx *Context) string { |
| 720 | var sb strings.Builder |
| 721 | |
| 722 | // System status |
| 723 | sb.WriteString(fmt.Sprintf("Time: %s | Period: #%d | Runtime: %d minutes\n\n", |
| 724 | ctx.CurrentTime, ctx.CallCount, ctx.RuntimeMinutes)) |
| 725 | |
| 726 | // BTC market |
| 727 | if btcData, hasBTC := ctx.MarketDataMap["BTCUSDT"]; hasBTC { |
| 728 | sb.WriteString(fmt.Sprintf("BTC: %.2f (1h: %+.2f%%, 4h: %+.2f%%) | MACD: %.4f | RSI: %.2f\n\n", |
| 729 | btcData.CurrentPrice, btcData.PriceChange1h, btcData.PriceChange4h, |
| 730 | btcData.CurrentMACD, btcData.CurrentRSI7)) |
| 731 | } |
| 732 | |
| 733 | // Account information |
| 734 | sb.WriteString(fmt.Sprintf("Account: Equity %.2f | Balance %.2f (%.1f%%) | PnL %+.2f%% | Margin %.1f%% | Positions %d\n\n", |
| 735 | ctx.Account.TotalEquity, |
| 736 | ctx.Account.AvailableBalance, |
| 737 | (ctx.Account.AvailableBalance/ctx.Account.TotalEquity)*100, |
| 738 | ctx.Account.TotalPnLPct, |
| 739 | ctx.Account.MarginUsedPct, |
| 740 | ctx.Account.PositionCount)) |
| 741 | |
| 742 | // Recently completed orders (placed before positions to ensure visibility) |
| 743 | if len(ctx.RecentOrders) > 0 { |
| 744 | sb.WriteString("## Recent Completed Trades\n") |
| 745 | for i, order := range ctx.RecentOrders { |
| 746 | resultStr := "Profit" |
| 747 | if order.RealizedPnL < 0 { |
| 748 | resultStr = "Loss" |
| 749 | } |
| 750 | sb.WriteString(fmt.Sprintf("%d. %s %s | Entry %.4f Exit %.4f | %s: %+.2f USDT (%+.2f%%) | %s→%s (%s)\n", |
| 751 | i+1, order.Symbol, order.Side, |
| 752 | order.EntryPrice, order.ExitPrice, |
| 753 | resultStr, order.RealizedPnL, order.PnLPct, |
| 754 | order.EntryTime, order.ExitTime, order.HoldDuration)) |
| 755 | } |
| 756 | sb.WriteString("\n") |
| 757 | } |
| 758 | |
| 759 | // Historical trading statistics (helps AI understand past performance) |
| 760 | if ctx.TradingStats != nil && ctx.TradingStats.TotalTrades > 0 { |
| 761 | // Get language from strategy config |
| 762 | lang := e.GetLanguage() |
| 763 | |
| 764 | // Win/Loss ratio |
| 765 | var winLossRatio float64 |
| 766 | if ctx.TradingStats.AvgLoss > 0 { |
| 767 | winLossRatio = ctx.TradingStats.AvgWin / ctx.TradingStats.AvgLoss |
| 768 | } |
| 769 | |
| 770 | if lang == LangChinese { |
| 771 | sb.WriteString("## Historical Trading Statistics\n") |
| 772 | sb.WriteString(fmt.Sprintf("Total Trades: %d | Profit Factor: %.2f | Sharpe: %.2f | Win/Loss Ratio: %.2f\n", |
| 773 | ctx.TradingStats.TotalTrades, |
| 774 | ctx.TradingStats.ProfitFactor, |
| 775 | ctx.TradingStats.SharpeRatio, |
| 776 | winLossRatio)) |
no test coverage detected