docs: Add Smart Entry Validation System to Common Pitfall #63
This commit is contained in:
61
.github/copilot-instructions.md
vendored
61
.github/copilot-instructions.md
vendored
@@ -4468,6 +4468,67 @@ trade.realizedPnL += actualRealizedPnL // NOT: result.realizedPnL from SDK
|
|||||||
- **Deployed:** Nov 24, 03:30 UTC (container restarted)
|
- **Deployed:** Nov 24, 03:30 UTC (container restarted)
|
||||||
- **Lesson:** When implementing feature flags, ALWAYS add ENV variables immediately. Code defaults are not enough - ENV must explicitly set values to override. Verify with test trade after deployment, not just code review.
|
- **Lesson:** When implementing feature flags, ALWAYS add ENV variables immediately. Code defaults are not enough - ENV must explicitly set values to override. Verify with test trade after deployment, not just code review.
|
||||||
|
|
||||||
|
63. **Smart Entry Validation System - Block & Watch (DEPLOYED - Nov 30, 2025):**
|
||||||
|
- **Purpose:** Recover profits from marginal quality signals (50-89) that would otherwise be blocked
|
||||||
|
- **Strategy:** Queue blocked signals, monitor 1-minute price action for 10 minutes, enter if price confirms direction
|
||||||
|
- **Implementation:** `lib/trading/smart-validation-queue.ts` (330+ lines)
|
||||||
|
- **Core Logic:**
|
||||||
|
* **Queue:** Signals with quality 50-89 (below 50 = hard block, 90+ = immediate execution)
|
||||||
|
* **Monitor:** Check price every 30 seconds using market data cache
|
||||||
|
* **Confirm:** LONG at +0.3% move, SHORT at -0.3% move → auto-execute via /api/trading/execute
|
||||||
|
* **Abandon:** LONG at -0.4% drawdown, SHORT at +0.4% rise → saved from potential loser
|
||||||
|
* **Expire:** After 10 minutes if no confirmation → signal ignored
|
||||||
|
* **Notifications:** Telegram messages for queued/confirmed/abandoned/expired/executed events
|
||||||
|
- **Integration Points:**
|
||||||
|
* check-risk endpoint: Calls `validationQueue.addSignal()` when quality score too low
|
||||||
|
* **CRITICAL:** Only applies to 5-minute trading signals (timeframe='5')
|
||||||
|
* **DOES NOT apply to 1-minute data collection** (timeframe='1' bypasses check-risk entirely)
|
||||||
|
* Startup: `lib/startup/index.ts` calls `startSmartValidation()`
|
||||||
|
* Market data: Uses `getMarketDataCache()` for real-time 1-minute prices
|
||||||
|
- **Example Flow:**
|
||||||
|
```
|
||||||
|
T+0: LONG signal at $137.545, quality 50
|
||||||
|
❌ Blocked from immediate execution
|
||||||
|
✅ Queued for validation
|
||||||
|
📱 Telegram: "⏰ SOL-PERP LONG blocked (quality 50) - monitoring for 10min"
|
||||||
|
|
||||||
|
T+3min: Price $138.10 (+0.41%) - CONFIRMATION HIT!
|
||||||
|
✅ Validates at +0.41% (exceeds +0.3% threshold)
|
||||||
|
📱 Telegram: "✅ SOL-PERP LONG VALIDATED - Price moved +0.41%"
|
||||||
|
🚀 Auto-executes trade at $138.10
|
||||||
|
📱 Telegram: "🚀 Validated trade EXECUTED - Trade ID: cm..."
|
||||||
|
|
||||||
|
Result: $138.10 → $140.01 = +1.38% profit
|
||||||
|
(vs blocked: $0 profit, vs full move: +1.79% = 77% capture rate)
|
||||||
|
```
|
||||||
|
- **Expected Impact:**
|
||||||
|
* Recover ~30% of blocked winners (+15 trades/month)
|
||||||
|
* Still filter ~70% of true losers via abandonment
|
||||||
|
* Estimated monthly recovery: +$1,823 profit
|
||||||
|
* Entry slippage: +0.3% from signal price (acceptable for 77% move capture)
|
||||||
|
- **Database Fields:** Trade table includes `validatedEntry: true`, `originalQualityScore`, `validationDelayMinutes` for analytics
|
||||||
|
- **Monitoring Commands:**
|
||||||
|
```bash
|
||||||
|
# Watch validation events
|
||||||
|
docker logs -f trading-bot-v4 | grep -E "(Smart validation|VALIDATED|ABANDONED|EXPIRED)"
|
||||||
|
|
||||||
|
# Check queue status
|
||||||
|
curl http://localhost:3001/api/trading/smart-validation-status
|
||||||
|
```
|
||||||
|
- **Safety Design:**
|
||||||
|
* Auto-start monitoring when first signal queued
|
||||||
|
* Auto-stop when queue empty (save resources)
|
||||||
|
* 30-second check interval (balance responsiveness vs overhead)
|
||||||
|
* Uses existing 1-minute data infrastructure (no new alerts needed)
|
||||||
|
* Confirmation threshold high enough to filter noise (+0.3% = ~$0.40 on $137 SOL)
|
||||||
|
* Abandonment threshold protects from reversals (-0.4% = ~$0.55 drawdown max)
|
||||||
|
- **Commit:** 7c9cfba "feat: Add Smart Entry Validation Queue system - Block & Watch for quality 50-89 signals"
|
||||||
|
- **Files:**
|
||||||
|
* `lib/trading/smart-validation-queue.ts` - Main queue implementation
|
||||||
|
* `lib/notifications/telegram.ts` - sendValidationNotification() function
|
||||||
|
* `app/api/trading/check-risk/route.ts` - Integration point (calls addSignal())
|
||||||
|
- **Lesson:** When building validation systems, use existing infrastructure (1-min data cache) instead of creating new dependencies. Confirmation via price action is more reliable than pre-filtering with strict thresholds. Balance between catching winners (0.3% confirms) and avoiding losers (0.4% abandons) requires tuning based on 50-100 validation outcomes.
|
||||||
|
|
||||||
## File Conventions
|
## File Conventions
|
||||||
|
|
||||||
- **API routes:** `app/api/[feature]/[action]/route.ts` (Next.js 15 App Router)
|
- **API routes:** `app/api/[feature]/[action]/route.ts` (Next.js 15 App Router)
|
||||||
|
|||||||
Reference in New Issue
Block a user