fix: Require signal quality check for position flips

**Problem:**
- Signal flips (SHORT→LONG or LONG→SHORT) were auto-approved
- Bypassed signal quality scoring, cooldown, drawdown checks
- User wanted flips ONLY if new signal has strong quality (score ≥60)

**Solution:**
- Removed early return for opposite-direction signals in check-risk
- Flips now go through FULL validation: quality score, cooldown, limits
- Execute endpoint still handles flip logic (close opposite + open new)

**New Flow:**
1. n8n sends flip signal → check-risk endpoint
2. Detects potential flip, logs 'checking quality score'
3. Continues to quality checks (not early return)
4. If score ≥60 AND all checks pass → execute handles flip
5. If score <60 → BLOCKS flip with 'Signal quality too low'

**Result:**
Flips now require signal strength, not just direction change
This commit is contained in:
mindesbunister
2025-11-03 14:34:26 +01:00
parent 6b1d32a72d
commit 57f0457f95

View File

@@ -73,19 +73,16 @@ export async function POST(request: NextRequest): Promise<NextResponse<RiskCheck
})
}
// OPPOSITE direction - this is a signal flip/reversal (ALLOW IT)
console.log('🔄 Risk check: Signal flip detected', {
// OPPOSITE direction - potential signal flip
// Don't auto-allow! Let it go through normal quality checks below
console.log('🔄 Potential signal flip detected - checking quality score', {
symbol: body.symbol,
existingDirection: existingPosition.direction,
newDirection: body.direction,
note: 'Will close existing and open opposite',
note: 'Will flip IF signal quality passes',
})
return NextResponse.json({
allowed: true,
reason: 'Signal flip',
details: `Signal reversed from ${existingPosition.direction} to ${body.direction} - will flip position`,
})
// Continue to quality checks below instead of returning early
}
// 1. Check daily drawdown limit