PROBLEM: - check-risk calculated quality score: 60, 70 (PASSED) - execute calculated quality score: 35, 45 (should have BLOCKED) - Two different functions with different logic caused trades to bypass validation ROOT CAUSE: Two separate scoring functions existed: 1. scoreSignalQuality() in check-risk (detailed, 95% price threshold) 2. calculateQualityScore() in execute (simpler, 90% price threshold) Example with pricePosition=96.4%, volumeRatio=0.9: - check-risk: Checks >95, volumeRatio>1.4 failed → -15 + bonuses = 60 ✅ PASSED - execute: Checks >90 → -15 + bonuses = 35 ❌ Should block but already opened SOLUTION: 1. Created lib/trading/signal-quality.ts with unified scoreSignalQuality() 2. Both endpoints now import and use SAME function 3. Consistent scoring logic: 95% price threshold, volume breakout bonus 4. Returns detailed reasons for debugging IMPACT: - Quality scores now MATCH between check-risk and execute - No more trades bypassing validation due to calculation differences - Better debugging with quality reasons logged Files changed: - NEW: lib/trading/signal-quality.ts (unified scoring function) - MODIFIED: app/api/trading/check-risk/route.ts (import shared function) - MODIFIED: app/api/trading/execute/route.ts (import shared function) - REMOVED: Duplicate calculateQualityScore() from execute - REMOVED: Duplicate scoreSignalQuality() from check-risk
21 KiB
21 KiB