fix: Increase transaction confirmation timeout to 60s for Alchemy Growth

- Alchemy Growth (10,000 CU/s) can handle longer confirmation waits
- Increased timeout from 30s to 60s in both openPosition() and closePosition()
- Added debug logging to execute endpoint to trace hang points
- Configured dual RPC: Alchemy primary (transactions), Helius fallback (subscriptions)
- Previous 30s timeout was causing premature failures during Solana congestion
- This should resolve 'Transaction was not confirmed in 30.00 seconds' errors

Related: User reported n8n webhook returning 500 with timeout error
This commit is contained in:
mindesbunister
2025-11-14 20:42:59 +01:00
parent 6dccea5d91
commit 78ab9e1a94
3 changed files with 42 additions and 10 deletions

View File

@@ -567,6 +567,17 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
// while orders are still being placed, leaving orphaned stop loss orders
let exitOrderSignatures: string[] = []
try {
console.log('🔍 DEBUG: About to call placeExitOrders()...')
console.log('🔍 DEBUG: Parameters:', {
symbol: driftSymbol,
positionSizeUSD,
entryPrice,
tp1Price,
tp2Price,
stopLossPrice,
direction: body.direction
})
const exitRes = await placeExitOrders({
symbol: driftSymbol,
positionSizeUSD: positionSizeUSD,
@@ -584,6 +595,8 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
hardStopPrice: hardStopPrice,
})
console.log('🔍 DEBUG: placeExitOrders() returned:', exitRes.success ? 'SUCCESS' : 'FAILED')
if (!exitRes.success) {
console.error('❌ Failed to place on-chain exit orders:', exitRes.error)
} else {
@@ -594,10 +607,13 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
console.error('❌ Unexpected error placing exit orders:', err)
}
console.log('🔍 DEBUG: Exit orders section complete, about to calculate quality score...')
// Save trade to database FIRST (CRITICAL: Must succeed before Position Manager)
let qualityResult
try {
// Calculate quality score if metrics available
console.log('🔍 DEBUG: Calling scoreSignalQuality()...')
qualityResult = await scoreSignalQuality({
atr: body.atr || 0,
adx: body.adx || 0,
@@ -610,6 +626,9 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
timeframe: body.timeframe,
})
console.log('🔍 DEBUG: scoreSignalQuality() completed, score:', qualityResult.score)
console.log('🔍 DEBUG: About to call createTrade()...')
await createTrade({
positionId: openResult.transactionSignature!,
symbol: driftSymbol,
@@ -643,6 +662,7 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
indicatorVersion: body.indicatorVersion || 'v5', // Default to v5 for backward compatibility
})
console.log('🔍 DEBUG: createTrade() completed successfully')
console.log(`💾 Trade saved with quality score: ${qualityResult.score}/100`)
console.log(`📊 Quality reasons: ${qualityResult.reasons.join(', ')}`)
} catch (dbError) {