4 Commits

Author SHA1 Message Date
mindesbunister
cd2171386d docs: Document Bug #87 Phase 2 deployment in v11 analysis
Added Phase 2 enhancement section at top of v11 analysis doc:
- Hybrid passive + active SL recovery approach
- User requirement specification
- Implementation details (30s passive, 60s/90s active recovery)
- attemptSLPlacement() function description
- Git commit reference and deployment timestamp

Deployment: Dec 15, 2025 13:30 UTC
Container: trading-bot-v4 (sha256:4eaef891...)
2025-12-16 15:26:35 +01:00
mindesbunister
c77d236842 docs: Update Bug #87 deployment status - OPERATIONAL 2025-12-16 14:50:48 +01:00
mindesbunister
aa16daffa2 critical: Fix Bug #87 - Add 3-tier SL verification with circuit breaker
CRITICAL FIX: Prevents silent stop-loss placement failures that caused $1,000+ losses

Created lib/safety/sl-verification.ts (334 lines):
 60s → 90s delays
- Queries Drift protocol directly via user.getOpenOrders()
- Filters SL orders: marketIndex + reduceOnly + TRIGGER_MARKET/LIMIT
- Circuit breaker: haltTrading() blocks new trades on verification failure
- Emergency shutdown: Force-closes position after 3 failed attempts
- Event-driven architecture: Triggered once post-open (not polling)
- Reduces Drift API calls by ~95% vs continuous polling

Integrated in app/api/trading/execute/route.ts:
- Line 54: Import shouldAcceptNewTrade for pre-execution check
- Lines 215-221: Circuit breaker validates trading allowed (HTTP 503 if halted)
- Lines 583-592: Triggers SL verification post-open (fire-and-forget)

Root Cause - Bug #76: Silent SL placement failure
Database Evidence: Trade cmj8abpjo00w8o407m3fndmx0
- tp1OrderTx: 'DsRv7E8vtAS4dKFmoQoTZMdiLTUju9cfmr9DPCgquP3V...'  EXISTS
- tp2OrderTx: '3cmYgGE828hZAhpepShXmpxqCTACFvXijqEjEzoed5PG...'  EXISTS
- slOrderTx: NULL 
- softStopOrderTx: NULL 
- hardStopOrderTx: NULL 

User Report: 'RISK MANAGEMENT WAS REMOVED WHEN PRICE WENT TO SL!!!!! POSITION STILL OPEN'
Reality: SL orders never placed from start (not cancelled later)

Solution Philosophy: 'better safe than sorry' - user's words
Safety: Query on-chain state directly, don't trust internal success flags

Deployed: 2025-12-16 13:50:18 UTC
Docker Image: SHA256:80fd45004e71fa490fc4f472b252ecb25db91c6d90948de1516646b12a00446f
Container: trading-bot-v4 restarted successfully
2025-12-16 14:50:18 +01:00
mindesbunister
da20e1802f feat: v11.1 - RSI 60-70 filter for LONGs based on 7-trade analysis
Data-driven update from v11 analysis (Dec 15, 2025):
- RSI 60-70 for LONG: 100% WR (+6.97 across 2 trades)
- RSI <60 for LONG: 0% WR (-2.10 across 2 trades)
- RSI 73.5 for LONG: Worst loss (-7.09 single trade)

Changes:
- rsiLongMin: 30 → 60 (filter weak momentum)
- rsiLongMax: 70 (keep existing limit, RSI filter may have been disabled)
- Added analysis doc: docs/V11_ANALYSIS_DEC15_2025.md

Small sample (7 trades) but RSI pattern is clear.
Need 15+ more trades to validate.
2025-12-15 12:37:15 +01:00