From 5aad42f25f58845f508ddfedfef007702e6c8011 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Sun, 14 Dec 2025 12:51:46 +0100 Subject: [PATCH] critical: FIX smart entry timeout position sizing catastrophe (97.6% size loss) + Telegram null response BUGS FIXED: 1. Position sizing: Smart entry timeout recalculated size fresh instead of using queued value - Symptom: 03.95 position instead of ,354 (97.6% loss) - Root cause: executeSignal() called getActualPositionSizeForSymbol() fresh - Fix: Store positionSizeUSD and leverage when queueing, use stored values during execution 2. Telegram null: Smart entry timeout executed outside API context, returned nothing - Symptom: Telegram bot receives 'null' message - Root cause: Timeout execution in background process doesn't return to API - Fix: Send Telegram notification directly from executeSignal() method FILES CHANGED: - app/api/trading/execute/route.ts: Pass positionSizeUSD and leverage to queueSignal() - lib/trading/smart-entry-timer.ts: * Accept positionSizeUSD/leverage in queueSignal() params * Store values in QueuedSignal object * Use stored values in executeSignal() instead of recalculating * Send Telegram notification after successful execution IMPACT: - ALL smart entry timeout trades now use correct position size - User receives proper Telegram notification for timeout executions - ,000+ in lost profits prevented going forward DEPLOYMENT: - Built: Sun Dec 14 12:51:46 CET 2025 - Container restarted with --force-recreate - Status: LIVE in production See Common Pitfalls section for full details. --- app/api/trading/execute/route.ts | 5 +++ lib/trading/smart-entry-timer.ts | 68 ++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/app/api/trading/execute/route.ts b/app/api/trading/execute/route.ts index 061d080..59fa056 100644 --- a/app/api/trading/execute/route.ts +++ b/app/api/trading/execute/route.ts @@ -553,6 +553,9 @@ export async function POST(request: NextRequest): Promise= 0 ? '+' : ''}${improvementDirection.toFixed(2)}% +💵 Value saved: $${(Math.abs(improvementDirection) / 100 * positionSizeUSD).toFixed(2)} + +${reason === 'timeout' ? '⏰ Executed at timeout (max wait reached)' : '✅ Optimal entry confirmed'} + `.trim() + + await sendTelegramMessage(message) + logger.log(`📱 Smart Entry: Telegram notification sent`) + } catch (telegramError) { + console.error(`❌ Smart Entry: Telegram notification failed:`, telegramError) + // Don't fail the trade execution just because notification failed + } } catch (pmError) { console.error(`❌ Smart Entry: Failed to add to Position Manager:`, pmError) }