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.
This commit is contained in:
@@ -553,6 +553,9 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
console.log(` Waiting for ${body.direction === 'long' ? 'dip' : 'bounce'} of ${pullbackMin}-${pullbackMax}%`)
|
||||
|
||||
// Queue the signal with CORRECTED signal price (current market price)
|
||||
// CRITICAL FIX (Dec 13, 2025): Pass positionSizeUSD and leverage to prevent recalculation on timeout
|
||||
// Bug: Timeout recalculates size fresh, gets $10.40 instead of $435 (97.6% loss)
|
||||
// Fix: Store calculated size when queueing, use stored value during execution
|
||||
const queuedSignal = smartEntryTimer.queueSignal({
|
||||
symbol: driftSymbol,
|
||||
direction: body.direction,
|
||||
@@ -564,6 +567,8 @@ export async function POST(request: NextRequest): Promise<NextResponse<ExecuteTr
|
||||
pricePosition: body.pricePosition,
|
||||
indicatorVersion: body.indicatorVersion,
|
||||
qualityScore: qualityResult.score,
|
||||
positionSizeUSD: positionSize, // CRITICAL: Store calculated USD size
|
||||
leverage: leverage, // CRITICAL: Store calculated leverage
|
||||
})
|
||||
|
||||
// Return success immediately (n8n workflow continues)
|
||||
|
||||
Reference in New Issue
Block a user