import { NextRequest, NextResponse } from 'next/server' import { getBlockedSignalTracker } from '@/lib/analysis/blocked-signal-tracker' /** * ONE-TIME BATCH PROCESSING ENDPOINT * * Purpose: Process all BlockedSignals that have completed their tracking window * using historical MarketData for minute-precision timing analysis. * * This endpoint: * 1. Finds signals NOT yet analyzed (analysisComplete = false) * 2. Verifies enough historical MarketData exists * 3. Analyzes minute-by-minute price movements * 4. Records EXACT timing when TP1/TP2/SL hit * 5. Updates database with findings * * Usage: curl http://localhost:3001/api/analytics/process-historical */ export async function POST(request: NextRequest) { try { console.log('🔄 API: Starting batch processing of historical data...') const tracker = getBlockedSignalTracker() // This will process all signals with enough historical data await tracker.processCompletedSignals() console.log('✅ API: Batch processing complete') return NextResponse.json({ success: true, message: 'Batch processing complete - check logs for details' }) } catch (error: any) { console.error('❌ API: Error in batch processing:', error) return NextResponse.json({ success: false, error: error.message, stack: error.stack }, { status: 500 }) } } /** * GET endpoint to check status */ export async function GET() { return NextResponse.json({ endpoint: '/api/analytics/process-historical', description: 'Batch process BlockedSignals using historical MarketData', method: 'POST', purpose: 'Minute-precision TP/SL timing analysis' }) }