-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: pass highest return rate and P&L metrics to AI decision prompt #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: pass highest return rate and P&L metrics to AI decision prompt #651
Conversation
🤖 Advisory Check ResultsThese are advisory checks to help improve code quality. They won't block your PR from being merged. 📋 PR InformationTitle Format: ✅ Good - Follows Conventional Commits 🔧 Backend ChecksGo Formatting: Files needing formattingGo Vet: ✅ Good Fix locally: go fmt ./... # Format code
go vet ./... # Check for issues
go test ./... # Run tests⚛️ Frontend ChecksBuild & Type Check: ✅ Success Fix locally: cd web
npm run build # Test build (includes type checking)📖 ResourcesQuestions? Feel free to ask in the comments! 🙏 These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml. |
代码审查报告 - PR #651📋 基本信息
1️⃣ 业务逻辑审查✅ 问题定义核心缺陷: AI决策时缺少关键盈亏指标
示例场景: ✅ 解决方案验证新增指标:
修复后AI提示词: 业务价值: ✅ 显著提升AI决策质量
2️⃣ 技术实现审查✅ 代码质量修改1: 添加
|
| 维度 | 评分 | 说明 |
|---|---|---|
| 业务价值 | ⭐⭐⭐⭐⭐ | 显著提升AI决策质量 |
| 技术实现 | ⭐⭐⭐⭐ | 代码正确,受限于现有cache key bug |
| 安全性 | ⭐⭐⭐⭐⭐ | 无新增安全风险 |
| 可维护性 | ⭐⭐⭐⭐⭐ | 代码简洁,易于理解 |
🎯 核心价值
- AI决策质量: 提供绝对盈亏金额和历史峰值,AI可做更精准的止盈止损决策
- 风险管理: AI可根据实际盈亏金额调整策略(区分小盈和大盈)
- 回撤检测: AI可识别收益率回撤(15%→10%),及时止盈
🔧 行动建议
必须修复: 无
强烈建议:
- 修复
peakPnLCache的key问题(使用symbol_side而非symbol) - 已有issue #652跟进 - 添加单元测试验证新字段正确传递到AI提示词
可选优化:
- 添加峰值收益率异常检测(如超过1000%)
- 在
PositionInfo结构体注释中说明峰值共享问题 - 考虑添加字段:
RealizedPnL(已平仓盈亏)供AI参考
🔍 关于已知Bug (#652)
PR作者已明确说明:
"
⚠️ There is a critical bug in the existing peakPnLCache implementation (NOT introduced by this PR): The cache uses symbol as key instead of symbol_side..."
评价: ✅ 处理得当
- PR聚焦于"传递现有指标给AI",不引入新问题
- 已知Bug已单独跟进(issue bug: peakPnLCache key should use 'symbol_side' instead of 'symbol' causing incorrect peak P&L for dual positions #652),分离关注点合理
- 即使峰值数据有误,仍优于完全不传递
总评: 这是一个高质量的改进,显著提升AI的决策信息完整性。代码简洁、逻辑清晰,建议合并。峰值缓存key的问题属于现有系统问题,应通过issue #652单独修复。
审查时间: 2025-11-08
审查者: Claude AI Code Reviewer
包含以下关键更新: - NoFxAiOS#769: Funding Rate缓存机制(减少90% API调用) - NoFxAiOS#819: 修复AI决策盈亏计算未考虑杠杆 - NoFxAiOS#651: 修复历史最高收益率未传递给AI - NoFxAiOS#817: 修复Docker重启数据丢失问题 - NoFxAiOS#823: 添加单元测试和CI覆盖率 - NoFxAiOS#784: Hook模块解耦 - 多个安全和bug修复 冲突解决: - LoginPage.tsx: 合并了两边的import语句 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
Fixes #652
PositionInfostruct and AI prompt contextChanges
decision/engine.go
PeakPnLPctfield toPositionInfostruct to store historical peak P&L percentagebuildUserPrompt()to include profit/loss amount in USDT and peak return rate in position displaytrader/auto_trader.go
buildTradingContext()to readpeakPnLCacheand populatePeakPnLPctfieldRLock) for thread-safe cache accessBefore (AI Prompt)
After (AI Prompt)
Known Issue
peakPnLCacheimplementation (NOT introduced by this PR):The cache uses
symbolas key instead ofsymbol_side, which causes incorrect peak P&L values when holding dual positions (both long and short) of the same symbol. This is documented in issue #652.This PR passes the cached peak values to AI as-is. The underlying cache key bug needs to be fixed separately.
Test plan
PeakPnLPctfield is correctly added toPositionInfostructpeakPnLCacheusingRLock