Commit Graph

5 Commits

Author SHA1 Message Date
mindesbunister
5aad42f25f 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.
2025-12-14 12:51:46 +01:00
mindesbunister
d637aac2d7 feat: Deploy HA auto-failover with database promotion
- Enhanced DNS failover monitor on secondary (72.62.39.24)
- Auto-promotes database: pg_ctl promote on failover
- Creates DEMOTED flag on primary via SSH (split-brain protection)
- Telegram notifications with database promotion status
- Startup safety script ready (integration pending)
- 90-second automatic recovery vs 10-30 min manual
- Zero-cost 95% enterprise HA benefit

Status: DEPLOYED and MONITORING (14:52 CET)
Next: Controlled failover test during maintenance
2025-12-12 15:54:03 +01:00
mindesbunister
302511293c feat: Add production logging gating (Phase 1, Task 1.1)
- Created logger utility with environment-based gating (lib/utils/logger.ts)
- Replaced 517 console.log statements with logger.log (71% reduction)
- Fixed import paths in 15 files (resolved comment-trapped imports)
- Added DEBUG_LOGS=false to .env
- Achieves 71% immediate log reduction (517/731 statements)
- Expected 90% reduction in production when deployed

Impact: Reduced I/O blocking, lower log volume in production
Risk: LOW (easy rollback, non-invasive)
Phase: Phase 1, Task 1.1 (Quick Wins - Console.log Production Gating)

Files changed:
- NEW: lib/utils/logger.ts (production-safe logging)
- NEW: scripts/replace-console-logs.js (automation tool)
- Modified: 15 lib/*.ts files (console.log → logger.log)
- Modified: .env (DEBUG_LOGS=false)

Next: Task 1.2 (Image Size Optimization)
2025-12-05 00:32:41 +01:00
mindesbunister
53c8c59c25 feat: Phase 7.2 Real-Time Quality Validation
FEATURE: Validate signal quality before Smart Entry execution
- Re-checks market conditions after pullback wait (2-4 min)
- Cancels trade if conditions degraded significantly

VALIDATION CHECKS (4):
1. ADX degradation: Cancel if drops >2 points (enhanced existing)
2. Volume collapse: Cancel if drops >40% (NEW - momentum fading)
3. RSI reversal: Cancel if LONG RSI <30 or SHORT RSI >70 (NEW)
4. MAGAP divergence: Cancel if wrong MA structure (NEW)

EXPECTED IMPACT:
- Block 5-10% of signals that degrade during Smart Entry wait
- Save $300-800 in prevented losses over 100 trades
- Prevent entries when ADX/volume/momentum weakens

FILES CHANGED:
- lib/trading/smart-entry-timer.ts (115 lines validation logic)
- lib/trading/market-data-cache.ts (added maGap to interface)

INTEGRATION: Works with Phase 7.1 Smart Entry Timer
- Smart Entry waits for pullback (2-4 min)
- Phase 7.2 validates quality before execution
- Cancels if conditions degraded, executes if maintained
2025-11-27 13:53:53 +01:00
mindesbunister
a8c1b2ca06 feat: Phase 2 Smart Entry Timing - COMPLETE
Implementation of 1-minute data enhancements Phase 2:
- Queue signals when price not at favorable pullback level
- Monitor every 15s for 0.15-0.5% pullback (LONG=dip, SHORT=bounce)
- Validate ADX hasn't dropped >2 points (trend still strong)
- Timeout at 2 minutes → execute at current price
- Expected improvement: 0.2-0.5% per trade = ,600-4,000 over 100 trades

Files:
- lib/trading/smart-entry-timer.ts (616 lines, zero TS errors)
- app/api/trading/execute/route.ts (integrated smart entry check)
- .env (SMART_ENTRY_* configuration, disabled by default)

Next steps:
- Test with SMART_ENTRY_ENABLED=true in development
- Monitor first 5-10 trades for improvement verification
- Enable in production after successful testing
2025-11-27 11:40:23 +01:00