fix: use Pyth price data for flip-flop context check
CRITICAL FIX: Previous implementation showed incorrect price movements (100% instead of 0.2%) because currentPrice wasn't available in check-risk endpoint. Changes: - app/api/trading/check-risk/route.ts: Fetch current price from Pyth price monitor before quality scoring - lib/trading/signal-quality.ts: Added validation and detailed logging - Check if currentPrice available, apply penalty if missing - Log actual prices: $X → $Y = Z% - Include prices in penalty/allowance messages Example outputs: Flip-flop in tight range: 4min ago, only 0.20% move ($143.86 → $143.58) (-25 pts) Direction change after 10.2% move ($170.00 → $153.00, 12min ago) - reversal allowed This fixes the false positive that allowed a 0.2% flip-flop earlier today. Deployed: 09:42 CET Nov 14, 2025
This commit is contained in:
@@ -312,6 +312,11 @@ export async function POST(request: NextRequest): Promise<NextResponse<RiskCheck
|
||||
|
||||
// 4. Check signal quality (if context metrics provided)
|
||||
if (hasContextMetrics) {
|
||||
// Get current price from Pyth for flip-flop price context check
|
||||
const priceMonitor = getPythPriceMonitor()
|
||||
const latestPrice = priceMonitor.getCachedPrice(body.symbol)
|
||||
const currentPrice = latestPrice?.price || body.currentPrice
|
||||
|
||||
const qualityScore = await scoreSignalQuality({
|
||||
atr: body.atr || 0,
|
||||
adx: body.adx || 0,
|
||||
@@ -320,7 +325,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<RiskCheck
|
||||
pricePosition: body.pricePosition || 0,
|
||||
direction: body.direction,
|
||||
symbol: body.symbol,
|
||||
currentPrice: body.currentPrice,
|
||||
currentPrice: currentPrice,
|
||||
timeframe: body.timeframe, // Pass timeframe for context-aware scoring
|
||||
minScore: config.minSignalQualityScore // Use config value
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user