critical: MANDATORY quality score check in execute endpoint
ROOT CAUSE:
- Execute endpoint calculated quality score but NEVER checked it
- After timeframe='5' validation, proceeded directly to execution
- TradingView sent signal with all metrics=0 (ADX, ATR, RSI, etc.)
- Quality scored as 30, but no threshold check existed
- Position opened with 909.77 size at quality 30 (need 90+ for LONG)
THE FIX:
- Added MANDATORY quality check after timeframe validation
- Blocks execution if score < minQualityScore (90 LONG, 95 SHORT)
- Returns HTTP 400 with detailed error message
- Logs Quality check passed OR ❌ QUALITY TOO LOW:
AFFECTED TRADES:
- cmihwkjmb0088m407lqd8mmbb: Quality 30 LONG (stopped out)
- cmih6ghn20002ql07zxfvna1l: Quality 50 LONG (stopped out)
- cmih5vrpu0001ql076mj3nm63: Quality 50 LONG (stopped out)
This is a FINANCIAL SAFETY critical fix - prevents low-quality trades.
This commit is contained in:
@@ -190,6 +190,25 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
|
||||
console.log(`✅ 5min signal confirmed - proceeding with trade execution`)
|
||||
|
||||
// CRITICAL FIX (Nov 27, 2025): Verify quality score meets minimum threshold
|
||||
// Bug: Quality 30 trade executed because no quality check after timeframe validation
|
||||
if (qualityResult.score < minQualityScore) {
|
||||
console.log(`❌ QUALITY TOO LOW: ${qualityResult.score} < ${minQualityScore} threshold for ${body.direction.toUpperCase()}`)
|
||||
console.log(` Reasons: ${qualityResult.reasons.join(', ')}`)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Quality score too low',
|
||||
message: `Signal quality ${qualityResult.score} below ${minQualityScore} minimum for ${body.direction.toUpperCase()} (reasons: ${qualityResult.reasons.join(', ')})`,
|
||||
quality: {
|
||||
score: qualityResult.score,
|
||||
threshold: minQualityScore,
|
||||
reasons: qualityResult.reasons
|
||||
}
|
||||
}, { status: 400 })
|
||||
}
|
||||
|
||||
console.log(`✅ Quality check passed: ${qualityResult.score} >= ${minQualityScore}`)
|
||||
|
||||
// Initialize Drift service and check account health before sizing
|
||||
const driftService = await initializeDriftService()
|
||||
const health = await driftService.getAccountHealth()
|
||||
|
||||
Reference in New Issue
Block a user