Track and display how long each position has been held to help AI make better timing decisions.
**Implementation**:
- Added UpdateTime field to PositionInfo struct (decision/engine.go:26)
- Added positionFirstSeenTime map to AutoTrader for tracking (trader/auto_trader.go:60)
- Record opening time when position is created successfully:
- executeOpenLongWithRecord: Records timestamp for long positions (trader/auto_trader.go:540-541)
- executeOpenShortWithRecord: Records timestamp for short positions (trader/auto_trader.go:593-594)
- Fallback tracking in buildTradingContext for program restart scenarios (trader/auto_trader.go:386-392)
- Auto-cleanup closed positions from tracking map (trader/auto_trader.go:409-414)
- Display duration in user prompt with smart formatting:
- Under 60 min: "持仓时长25分钟"
- Over 60 min: "持仓时长2小时15分钟"
**Example Output**:
```
1. TAOUSDT LONG | 入场价435.5300 当前价433.1900 | 盈亏-0.54% | 杠杆20x | 保证金25 | 强平价418.1528 | 持仓时长2小时15分钟
```
**Benefits**:
- AI can see how long positions have been held
- Helps enforce minimum holding period (30-60 min) from system prompt
- Simple implementation with minimal overhead
- Auto-cleanup prevents memory leaks
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Major improvements to the AI trading decision engine:
**Core Changes in decision/engine.go** (175 lines modified):
1. **Sharpe Ratio Optimization Focus**
- Restructured system prompt to emphasize Sharpe ratio maximization
- Added clear guidance: high-quality trades over frequent trading
- Explained that 3-minute scan interval ≠ trade every cycle
2. **Trading Frequency Controls**
- Defined optimal frequency: 2-4 trades/day (0.1-0.2 trades/hour)
- Over-trading threshold: >2 trades/hour indicates issues
- Minimum holding period: 30-60 minutes per position
3. **Long/Short Balance Incentives**
- Emphasized equal profit potential for long and short positions
- Removed long-bias with explicit short trading encouragement
- Clear guidance: uptrend→long, downtrend→short, sideways→wait
4. **Stricter Entry Signal Standards**
- Strong signals only: confidence ≥75, multi-indicator confirmation
- Weak signals explicitly discouraged (single indicator, unclear trend)
- Self-check mechanism to prevent premature re-entry (<30min)
5. **Enhanced Sharpe Ratio Feedback Loop**
- Sharpe < -0.5: Stop trading for 6+ cycles (18min), deep reflection
- Sharpe -0.5~0: Strict control, confidence >80 only
- Sharpe 0~0.7: Maintain current strategy
- Sharpe >0.7: Consider position size increase
6. **Risk-Reward Ratio Validation**
- Added hard constraint: R:R must be ≥ 3.0:1
- Automatic calculation and validation in `validateDecision()`
- Rejects trades with insufficient risk-reward ratio
7. **Improved Prompt Structure**
- More organized sections with clear headers
- Actionable guidance instead of abstract principles
- Better examples for JSON output format
**Impact**: These changes should significantly improve trading quality,
reduce over-trading, and increase Sharpe ratio through better risk management
and trade selection discipline.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Architecture improvements:
- Extract AI decision engine to dedicated `decision` package
- Create `mcp` package for Model Context Protocol client
- Separate market data structures into `market/data.go`
- Update trader to use new modular structure
New packages:
- `decision/engine.go` - AI decision logic and prompt building
- `mcp/client.go` - Unified AI API client (DeepSeek/Qwen)
- `market/data.go` - Market data type definitions
Benefits:
- Better separation of concerns
- Improved code organization and maintainability
- Easier to test individual components
- More flexible AI provider integration
- Cleaner dependency management
Updated imports:
- trader/auto_trader.go now uses decision and mcp packages
- Consistent API across different AI providers
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>