feat: Add multi-timeframe data collection to execute endpoint
- Only 5min signals execute trades (production) - 15min/1H/4H/Daily signals saved to BlockedSignal table for analysis - Enables cross-timeframe performance comparison - Zero financial risk - non-5min signals just collect data - blockReason: 'DATA_COLLECTION_ONLY' for easy filtering - Returns HTTP 200 (not 400) since this is expected behavior - Prepares for future timeframe optimization decisions
This commit is contained in:
@@ -105,6 +105,52 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
console.log(`📊 Market data auto-cached for ${driftSymbol} from trade signal`)
|
||||
}
|
||||
|
||||
// 🔬 MULTI-TIMEFRAME DATA COLLECTION
|
||||
// Only execute trades from 5min timeframe, save other timeframes for analysis
|
||||
const timeframe = body.timeframe || '5'
|
||||
if (timeframe !== '5') {
|
||||
console.log(`📊 DATA COLLECTION: ${timeframe}min signal from ${driftSymbol}, saving for analysis (not executing)`)
|
||||
|
||||
// Save to BlockedSignal for cross-timeframe analysis
|
||||
const { createBlockedSignal } = await import('@/lib/database/trades')
|
||||
try {
|
||||
await createBlockedSignal({
|
||||
symbol: driftSymbol,
|
||||
direction: body.direction,
|
||||
blockReason: 'DATA_COLLECTION_ONLY',
|
||||
blockDetails: `Multi-timeframe data collection: ${timeframe}min signals saved but not executed (only 5min executes)`,
|
||||
atr: body.atr,
|
||||
adx: body.adx,
|
||||
rsi: body.rsi,
|
||||
volumeRatio: body.volumeRatio,
|
||||
pricePosition: body.pricePosition,
|
||||
timeframe: timeframe,
|
||||
currentPrice: body.signalPrice || 0,
|
||||
signalQualityScore: 0, // Not scored since not executed
|
||||
signalQualityVersion: 'data-collection',
|
||||
minScoreRequired: 0,
|
||||
scoreBreakdown: {},
|
||||
})
|
||||
console.log(`✅ ${timeframe}min signal saved to database for future analysis`)
|
||||
} catch (dbError) {
|
||||
console.error(`❌ Failed to save ${timeframe}min signal:`, dbError)
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Data collection only',
|
||||
message: `Signal from ${timeframe}min timeframe saved for analysis. Only 5min signals are executed. Check BlockedSignal table for data.`,
|
||||
dataCollection: {
|
||||
timeframe: timeframe,
|
||||
symbol: driftSymbol,
|
||||
direction: body.direction,
|
||||
saved: true,
|
||||
}
|
||||
}, { status: 200 }) // 200 not 400 - this is expected behavior
|
||||
}
|
||||
|
||||
console.log(`✅ 5min signal confirmed - proceeding with trade execution`)
|
||||
|
||||
// Get trading configuration
|
||||
const config = getMergedConfig()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user