diff --git a/.env b/.env
index 607a54d..e6b3b6f 100644
--- a/.env
+++ b/.env
@@ -393,7 +393,7 @@ TRAILING_STOP_PERCENT=0.5
TRAILING_STOP_ACTIVATION=0.4
MIN_SIGNAL_QUALITY_SCORE=91
MIN_SIGNAL_QUALITY_SCORE_LONG=90
-MIN_SIGNAL_QUALITY_SCORE_SHORT=80
+MIN_SIGNAL_QUALITY_SCORE_SHORT=95
# Adaptive Leverage System (Nov 24, 2025)
# ENABLED Dec 1, 2025: 10x for high-quality signals, 5x for borderline
# Direction-specific thresholds: LONG ≥95, SHORT ≥90
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 5659b5f..b5fc2e9 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -1997,6 +1997,237 @@ const { size, leverage } = getActualPositionSizeForSymbol(driftSymbol, config, q
// leverage is now 15x for quality ≥95, or 10x for quality 90-94
```
+## Environment Variable Reference
+
+**Purpose:** Centralized reference for all environment variables used in the trading bot system. This table provides quick lookup for AI agents and developers without needing to read the entire 482-line .env file or search multiple documentation sections.
+
+**Source:** `.env` file with comprehensive inline documentation. Variables organized by functional category matching .env structure.
+
+**Configuration Priority:**
+1. **Per-symbol ENV vars** (highest priority): `SOLANA_*`, `ETHEREUM_*`
+2. **Market-specific config**: From `MARKET_CONFIGS` in config/trading.ts
+3. **Global ENV vars**: Fallback for BTC and other symbols
+4. **Default config**: Lowest priority in `DEFAULT_TRADING_CONFIG`
+
+### Required - Drift Protocol Trading
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `DRIFT_WALLET_PRIVATE_KEY` | - | Private key for Drift Protocol wallet | String (JSON array or base58) | **REQUIRED** - Supports both formats from Phantom wallet |
+| `API_SECRET_KEY` | - | Authentication token for trading endpoints | String | **REQUIRED** - Used in `Authorization: Bearer` header |
+
+### Required - Solana RPC Endpoint
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `SOLANA_RPC_URL` | - | Primary Solana RPC endpoint URL | URL | **REQUIRED** - Use Helius for reliability (NOT Alchemy - see Common Pitfall #2) |
+| `BACKUP_RPC_URL` | - | Fallback RPC endpoint | URL | Optional - Used if primary fails |
+
+### Required - Pyth Network
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `PYTH_HERMES_URL` | `https://hermes.pyth.network` | Pyth price feed endpoint | URL | **REQUIRED** - Real-time price data for position monitoring |
+
+### Trading Configuration - Signal Quality
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `MIN_SIGNAL_QUALITY_SCORE` | `60` | Global minimum quality threshold | Integer (0-100) | **DEPRECATED** - Use direction-specific thresholds |
+| `MIN_SIGNAL_QUALITY_SCORE_LONG` | `90` | Minimum quality for LONG signals | Integer (0-100) | **PRODUCTION** - Raised Nov 28, 2025 |
+| `MIN_SIGNAL_QUALITY_SCORE_SHORT` | `80` | Minimum quality for SHORT signals | Integer (0-100) | **PRODUCTION** - Lower threshold due to baseline difficulty |
+
+### Trading Configuration - Adaptive Leverage
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `USE_ADAPTIVE_LEVERAGE` | `true` | Enable quality-based leverage adjustment | Boolean | **ACTIVE** - Dec 1, 2025 production config |
+| `HIGH_QUALITY_LEVERAGE` | `10` | Leverage for high-quality signals | Integer | Applied when quality ≥ threshold |
+| `LOW_QUALITY_LEVERAGE` | `5` | Leverage for borderline signals | Integer | Applied when quality < threshold but ≥ minimum |
+| `QUALITY_LEVERAGE_THRESHOLD` | `95` | Global quality threshold for high leverage | Integer (0-100) | **DEPRECATED** - Use direction-specific |
+| `QUALITY_LEVERAGE_THRESHOLD_LONG` | `95` | LONG quality threshold for 10x leverage | Integer (0-100) | **PRODUCTION** - Independent control |
+| `QUALITY_LEVERAGE_THRESHOLD_SHORT` | `90` | SHORT quality threshold for 10x leverage | Integer (0-100) | **PRODUCTION** - Lower threshold for SHORTs |
+
+### Trading Configuration - Position Sizing
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `MAX_POSITION_SIZE_USD` | `100` | Global position size fallback | Integer (USD) | Used for BTC and other symbols |
+| `LEVERAGE` | `1` | Global leverage fallback | Integer | Used for BTC and other symbols |
+| `SOLANA_ENABLED` | `true` | Enable SOL-PERP trading | Boolean | Independent on/off toggle |
+| `SOLANA_POSITION_SIZE` | `100` | SOL position size percentage | Integer (1-100) | 100% = use all free collateral |
+| `SOLANA_LEVERAGE` | `15` | SOL leverage multiplier | Integer | **PRODUCTION** - Higher risk, higher reward |
+| `ETHEREUM_ENABLED` | `false` | Enable ETH-PERP trading | Boolean | Typically disabled (SOL primary) |
+| `ETHEREUM_POSITION_SIZE` | `100` | ETH position size percentage | Integer (1-100) | |
+| `ETHEREUM_LEVERAGE` | `1` | ETH leverage multiplier | Integer | Lower leverage for data collection |
+
+### ATR-Based TP/SL System
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `USE_ATR_BASED_TARGETS` | `true` | Enable ATR-based TP/SL calculation | Boolean | **ACTIVE** - Regime-agnostic system |
+| `ATR_MULTIPLIER_TP1` | `2.0` | ATR multiplier for TP1 target | Float | Typically ~0.86% for SOL (ATR 0.43) |
+| `ATR_MULTIPLIER_TP2` | `4.0` | ATR multiplier for TP2 target | Float | Typically ~1.72% for SOL |
+| `ATR_MULTIPLIER_SL` | `3.0` | ATR multiplier for stop loss | Float | Typically ~1.29% for SOL |
+| `MIN_TP1_PERCENT` | `0.5` | Safety floor for TP1 | Float (%) | Prevents too-tight targets |
+| `MAX_TP1_PERCENT` | `1.5` | Safety ceiling for TP1 | Float (%) | Prevents extreme targets |
+| `MIN_TP2_PERCENT` | `1.0` | Safety floor for TP2 | Float (%) | |
+| `MAX_TP2_PERCENT` | `3.0` | Safety ceiling for TP2 | Float (%) | |
+| `MIN_SL_PERCENT` | `0.8` | Safety floor for SL | Float (%) | |
+| `MAX_SL_PERCENT` | `2.0` | Safety ceiling for SL | Float (%) | |
+| `TRAILING_STOP_ATR_MULTIPLIER` | `1.5` | ATR multiplier for trailing stop distance | Float | **Phase 7.3** - Adaptive with ADX |
+| `MIN_TRAILING_STOP_PERCENT` | `0.25` | Minimum trailing distance | Float (%) | Prevents too-tight trailing |
+| `MAX_TRAILING_STOP_PERCENT` | `0.9` | Maximum trailing distance | Float (%) | |
+
+### ATR-Based TP/SL - Legacy Fallback
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `STOP_LOSS_PERCENT` | `-1.5` | Fixed stop loss (when ATR unavailable) | Float (%) | Legacy fallback only |
+| `TAKE_PROFIT_1_PERCENT` | `0.8` | Fixed TP1 (when ATR unavailable) | Float (%) | Less optimal than ATR-based |
+| `TAKE_PROFIT_2_PERCENT` | `0.7` | Fixed TP2 (when ATR unavailable) | Float (%) | |
+
+### Trading Configuration - Runner System
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `TAKE_PROFIT_1_SIZE_PERCENT` | `60` | Percentage to close at TP1 | Integer (1-100) | Runner = 100 - this value (40% default) |
+| `TRAILING_STOP_PERCENT` | `0.3` | Fixed trailing stop distance | Float (%) | **DEPRECATED** - Use ATR-based |
+| `PROFIT_LOCK_TRIGGER_PERCENT` | `1.2` | Profit level to move SL to breakeven | Float (%) | Risk-free point |
+| `PROFIT_LOCK_SL_PERCENT` | `0.5` | Where to move SL after profit lock | Float (%) | Small profit protection |
+| `TRAILING_STOP_ACTIVATION_PERCENT` | `0.5` | When to start trailing stop | Float (%) | After TP2 trigger |
+| `SOFT_STOP_PERCENT` | `-1.5` | Dual stop system - trigger limit | Float (%) | Avoids wicks |
+| `HARD_STOP_PERCENT` | `-2.5` | Dual stop system - trigger market | Float (%) | Guarantees exit |
+
+### Trading Configuration - Dual Stop System
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `USE_DUAL_STOPS` | `true` | Enable dual stop loss orders | Boolean | Soft (limit) + hard (market) |
+| `SOFT_STOP_PERCENT` | `-1.5` | Soft stop trigger (limit order) | Float (%) | Avoids wick stops |
+| `HARD_STOP_PERCENT` | `-2.5` | Hard stop trigger (market order) | Float (%) | Guarantees exit |
+
+### Smart Entry Timing System
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `SMART_ENTRY_ENABLED` | `true` | Enable pullback detection system | Boolean | Wait for better entry prices |
+| `SMART_ENTRY_MAX_WAIT_MS` | `300000` | Maximum wait time for pullback | Integer (ms) | 5 minutes default |
+| `SMART_ENTRY_PULLBACK_MIN` | `0.5` | Minimum pullback to wait for | Float (%) | |
+| `SMART_ENTRY_PULLBACK_MAX` | `2.0` | Maximum pullback to wait for | Float (%) | |
+
+### Risk Limits & Execution
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `EMERGENCY_STOP_PERCENT` | `-2.0` | Emergency market close trigger | Float (%) | Immediate exit at any price |
+| `MAX_DAILY_DRAWDOWN` | `-5.0` | Daily loss limit | Float (%) | Stops trading for 24h |
+| `MAX_TRADES_PER_HOUR` | `10` | Hourly trade limit | Integer | Prevents overtrading |
+| `COOLDOWN_PERIOD_MS` | `300000` | Cooldown between trades | Integer (ms) | Per-symbol, 5 minutes default |
+
+### N8N Workflow Integration
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `N8N_WEBHOOK_URL` | - | N8N workflow webhook endpoint | URL | Optional - For workflow automation |
+| `N8N_ENABLED` | `false` | Enable n8n integration | Boolean | |
+
+### Notifications - Telegram
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `TELEGRAM_BOT_TOKEN` | - | Telegram bot authentication token | String | **REQUIRED** for notifications |
+| `TELEGRAM_CHAT_ID` | - | Telegram chat ID for notifications | String | **REQUIRED** - Get from @userinfobot |
+
+### Database Configuration
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `DATABASE_URL` | - | PostgreSQL connection string | String | **REQUIRED** - Format: postgresql://user:pass@host:port/db |
+| `POSTGRES_USER` | `postgres` | Database username | String | Used in docker-compose |
+| `POSTGRES_PASSWORD` | - | Database password | String | **REQUIRED** - Generate secure password |
+| `POSTGRES_DB` | `trading_bot_v4` | Database name | String | |
+
+### Security & Access Control
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `JWT_SECRET` | - | JWT token signing secret | String | **REQUIRED** - Generate random string |
+| `ENCRYPTION_KEY` | - | Data encryption key | String | **REQUIRED** - For sensitive data |
+
+### Development & Debugging
+
+| Variable | Default | Purpose | Type | Notes |
+|----------|---------|---------|------|-------|
+| `NODE_ENV` | `production` | Runtime environment | String | `development` \| `production` \| `test` |
+| `LOG_LEVEL` | `info` | Logging verbosity | String | `debug` \| `info` \| `warn` \| `error` |
+| `DRY_RUN` | `false` | Test mode without real trades | Boolean | **CRITICAL** - Test changes safely |
+| `PORT` | `3000` | Internal Next.js port | Integer | Container port, not exposed |
+| `NEXT_PUBLIC_API_URL` | `http://localhost:3001` | Public API base URL | URL | For frontend API calls |
+
+### Usage Examples
+
+**CORRECT: Use merged config (always)**
+```typescript
+import { getMergedConfig } from '@/config/trading'
+const config = getMergedConfig()
+
+// Access values through config object
+const minQuality = config.minSignalQualityScore
+const leverage = config.leverage
+```
+
+**WRONG: Never read ENV directly in business logic**
+```typescript
+// ❌ DON'T DO THIS
+const minQuality = process.env.MIN_SIGNAL_QUALITY_SCORE
+const leverage = parseInt(process.env.LEVERAGE || '1')
+```
+
+**Per-Symbol Position Sizing:**
+```typescript
+import { getPositionSizeForSymbol } from '@/config/trading'
+
+// Returns { size, leverage, enabled } for symbol
+const { size, leverage, enabled } = getPositionSizeForSymbol('SOL-PERP', config)
+
+if (!enabled) {
+ return NextResponse.json({ error: 'Symbol trading disabled' }, { status: 400 })
+}
+
+// Use symbol-specific values
+console.log(`Opening ${size} USD position at ${leverage}x leverage`)
+```
+
+**Adaptive Leverage Integration:**
+```typescript
+import { getLeverageForQualityScore } from '@/config/trading'
+
+// Calculate quality score first
+const qualityResult = scoreSignalQuality({ atr, adx, rsi, volumeRatio, pricePosition, timeframe })
+
+// Get adaptive leverage based on quality
+const leverage = getLeverageForQualityScore(qualityResult.score, config)
+// Returns: 10x for quality ≥95 (LONG) or ≥90 (SHORT), 5x for borderline
+
+// Use in position sizing
+const { size } = getActualPositionSizeForSymbol(driftSymbol, config, qualityResult.score)
+```
+
+**Symbol Normalization:**
+```typescript
+import { normalizeTradingViewSymbol } from '@/config/trading'
+
+// TradingView sends: "SOLUSDT", "ETHUSDT", "BTCUSDT"
+const tvSymbol = body.symbol // "SOLUSDT"
+
+// Normalize to Drift format
+const driftSymbol = normalizeTradingViewSymbol(tvSymbol) // Returns: "SOL-PERP"
+
+// Use Drift format in all trading operations
+const position = await driftService.getPosition(driftSymbol)
+```
+
## API Endpoints Architecture
**Authentication:** All `/api/trading/*` endpoints (except `/test`) require `Authorization: Bearer API_SECRET_KEY`
diff --git a/app/api/cluster/status/route.ts b/app/api/cluster/status/route.ts
index 2e26011..07b6222 100644
--- a/app/api/cluster/status/route.ts
+++ b/app/api/cluster/status/route.ts
@@ -84,25 +84,27 @@ async function getExplorationData() {
driver: sqlite3.Database
})
- // Get total combos and chunk statistics
- const totalCombosRow = await db.get('SELECT SUM(total_combos) as total FROM chunks')
+ // UPDATED (Dec 3, 2025): Track comprehensive v9_advanced sweep (1,693 chunks, 1.693M combos)
+ // Get total combos and chunk statistics from v9_advanced tables
+ // NOTE: v9_advanced_chunks uses start_combo/end_combo (not chunk_start/chunk_end)
+ const totalCombosRow = await db.get('SELECT SUM(total_combos) as total FROM v9_advanced_chunks')
const totalCombos = totalCombosRow?.total || 0
- const chunks = await db.all('SELECT * FROM chunks ORDER BY chunk_start')
+ const chunks = await db.all('SELECT * FROM v9_advanced_chunks ORDER BY start_combo')
const completedChunks = chunks.filter(c => c.status === 'completed').length
const runningChunks = chunks.filter(c => c.status === 'running').length
const pendingChunks = chunks.filter(c => c.status === 'pending').length
- // Try to get strategies (table may not exist yet)
+ // Try to get strategies from v9_advanced_strategies table
let strategies: any[] = []
let testedCombos = 0
try {
- const strategiesCount = await db.get('SELECT COUNT(*) as count FROM strategies')
+ const strategiesCount = await db.get('SELECT COUNT(*) as count FROM v9_advanced_strategies')
testedCombos = strategiesCount?.count || 0
strategies = await db.all(`
- SELECT * FROM strategies
+ SELECT * FROM v9_advanced_strategies
WHERE total_trades >= 700
ORDER BY pnl_per_1k DESC
LIMIT 10
diff --git a/app/cluster/page.tsx b/app/cluster/page.tsx
index 3a01145..f0ff850 100644
--- a/app/cluster/page.tsx
+++ b/app/cluster/page.tsx
@@ -282,30 +282,38 @@ export default function ClusterPage() {
{/* Exploration Progress */}
📊 Parameter Exploration
-
-
-
Total Combinations
-
{status.exploration.totalCombinations.toLocaleString()}
+
+ {/* Main Stats Grid */}
+
+
+
Total Combinations
+
+ {status.exploration.totalCombinations.toLocaleString()}
+
+
v9 comprehensive sweep
-
-
Tested
-
{status.exploration.testedCombinations.toLocaleString()}
+
+
+
Tested
+
+ {status.exploration.testedCombinations.toLocaleString()}
+
+
strategies evaluated
-
-
Chunks
-
- {status.exploration.chunks.completed} / {status.exploration.chunks.total}
- {status.exploration.chunks.running > 0 && (
-
({status.exploration.chunks.running} running)
- )}
- {status.exploration.chunks.pending > 0 && status.exploration.chunks.running === 0 && (
-
({status.exploration.chunks.pending} pending)
- )}
+
+
+
Chunks Progress
+
+ {status.exploration.chunks.completed}
+
+
+ of {status.exploration.chunks.total.toLocaleString()} completed
-
-
Status
-
+
+
+
Status
+
{status.exploration.chunks.running > 0 ? (
⚡ Processing
) : status.exploration.chunks.pending > 0 ? (
@@ -316,19 +324,61 @@ export default function ClusterPage() {
⏸️ Idle
)}
+
+ {status.exploration.chunks.running > 0 && `${status.exploration.chunks.running} chunks running`}
+ {status.exploration.chunks.running === 0 && status.exploration.chunks.pending > 0 && `${status.exploration.chunks.pending.toLocaleString()} chunks pending`}
+
-
-
+
+ {/* Chunk Status Breakdown */}
+
+
+
+ {status.exploration.chunks.completed}
+
+
✓ Completed
+
+
+
+ {status.exploration.chunks.running}
+
+
⏳ Running
+
+
+
+ {status.exploration.chunks.pending.toLocaleString()}
+
+
⏸️ Pending
+
-
- {status.exploration.progress.toFixed(2)}% complete
- {status.exploration.testedCombinations > 0 && (
-
({status.exploration.testedCombinations.toLocaleString()} strategies tested)
- )}
+
+ {/* Progress Bar */}
+
+
+ Overall Progress
+
+ {status.exploration.progress > 0 ? status.exploration.progress.toFixed(2) : '0.00'}%
+
+
+
+
+ {status.exploration.progress > 2 && (
+
+ {status.exploration.progress.toFixed(1)}%
+
+ )}
+
+
+
+ {status.exploration.chunks.completed.toLocaleString()} / {status.exploration.chunks.total.toLocaleString()} chunks processed
+ {status.exploration.testedCombinations > 0 && (
+ • {status.exploration.testedCombinations.toLocaleString()} strategies evaluated
+ )}
+
diff --git a/cluster/exploration.db b/cluster/exploration.db
index c736014..f923611 100644
Binary files a/cluster/exploration.db and b/cluster/exploration.db differ
diff --git a/TRADING_GOALS.md b/docs/TRADING_GOALS.md
similarity index 100%
rename from TRADING_GOALS.md
rename to docs/TRADING_GOALS.md
diff --git a/ANALYTICS_STATUS_AND_NEXT_STEPS.md b/docs/analysis/ANALYTICS_STATUS_AND_NEXT_STEPS.md
similarity index 100%
rename from ANALYTICS_STATUS_AND_NEXT_STEPS.md
rename to docs/analysis/ANALYTICS_STATUS_AND_NEXT_STEPS.md
diff --git a/BLOCKED_SIGNALS_TRACKING.md b/docs/analysis/BLOCKED_SIGNALS_TRACKING.md
similarity index 100%
rename from BLOCKED_SIGNALS_TRACKING.md
rename to docs/analysis/BLOCKED_SIGNALS_TRACKING.md
diff --git a/BLOCKED_SIGNAL_ANALYSIS_DEC2.md b/docs/analysis/BLOCKED_SIGNAL_ANALYSIS_DEC2.md
similarity index 100%
rename from BLOCKED_SIGNAL_ANALYSIS_DEC2.md
rename to docs/analysis/BLOCKED_SIGNAL_ANALYSIS_DEC2.md
diff --git a/BLOCKED_SIGNAL_CORRECTED_ANALYSIS_DEC2.md b/docs/analysis/BLOCKED_SIGNAL_CORRECTED_ANALYSIS_DEC2.md
similarity index 100%
rename from BLOCKED_SIGNAL_CORRECTED_ANALYSIS_DEC2.md
rename to docs/analysis/BLOCKED_SIGNAL_CORRECTED_ANALYSIS_DEC2.md
diff --git a/CLEANUP_PLAN.md b/docs/analysis/CLEANUP_PLAN.md
similarity index 100%
rename from CLEANUP_PLAN.md
rename to docs/analysis/CLEANUP_PLAN.md
diff --git a/DIAGNOSTIC_RESULTS_SUMMARY.md b/docs/analysis/DIAGNOSTIC_RESULTS_SUMMARY.md
similarity index 100%
rename from DIAGNOSTIC_RESULTS_SUMMARY.md
rename to docs/analysis/DIAGNOSTIC_RESULTS_SUMMARY.md
diff --git a/LONG_ADAPTIVE_LEVERAGE_VERIFICATION.md b/docs/analysis/LONG_ADAPTIVE_LEVERAGE_VERIFICATION.md
similarity index 100%
rename from LONG_ADAPTIVE_LEVERAGE_VERIFICATION.md
rename to docs/analysis/LONG_ADAPTIVE_LEVERAGE_VERIFICATION.md
diff --git a/PROFIT_PROJECTION_NOV24_2025.md b/docs/analysis/PROFIT_PROJECTION_NOV24_2025.md
similarity index 100%
rename from PROFIT_PROJECTION_NOV24_2025.md
rename to docs/analysis/PROFIT_PROJECTION_NOV24_2025.md
diff --git a/QUALITY_90_TP1_ONLY_ANALYSIS.md b/docs/analysis/QUALITY_90_TP1_ONLY_ANALYSIS.md
similarity index 100%
rename from QUALITY_90_TP1_ONLY_ANALYSIS.md
rename to docs/analysis/QUALITY_90_TP1_ONLY_ANALYSIS.md
diff --git a/RECOVERY_PLAN.md b/docs/analysis/RECOVERY_PLAN.md
similarity index 100%
rename from RECOVERY_PLAN.md
rename to docs/analysis/RECOVERY_PLAN.md
diff --git a/SAFETY_ANALYSIS.md b/docs/analysis/SAFETY_ANALYSIS.md
similarity index 100%
rename from SAFETY_ANALYSIS.md
rename to docs/analysis/SAFETY_ANALYSIS.md
diff --git a/SHORT_ADAPTIVE_LEVERAGE_IMPLEMENTED.md b/docs/analysis/SHORT_ADAPTIVE_LEVERAGE_IMPLEMENTED.md
similarity index 100%
rename from SHORT_ADAPTIVE_LEVERAGE_IMPLEMENTED.md
rename to docs/analysis/SHORT_ADAPTIVE_LEVERAGE_IMPLEMENTED.md
diff --git a/SIGNAL_QUALITY_TEST_RESULTS.md b/docs/analysis/SIGNAL_QUALITY_TEST_RESULTS.md
similarity index 100%
rename from SIGNAL_QUALITY_TEST_RESULTS.md
rename to docs/analysis/SIGNAL_QUALITY_TEST_RESULTS.md
diff --git a/ADAPTIVE_LEVERAGE_SYSTEM.md b/docs/architecture/ADAPTIVE_LEVERAGE_SYSTEM.md
similarity index 100%
rename from ADAPTIVE_LEVERAGE_SYSTEM.md
rename to docs/architecture/ADAPTIVE_LEVERAGE_SYSTEM.md
diff --git a/ATR_TRAILING_STOP_FIX.md b/docs/architecture/ATR_TRAILING_STOP_FIX.md
similarity index 100%
rename from ATR_TRAILING_STOP_FIX.md
rename to docs/architecture/ATR_TRAILING_STOP_FIX.md
diff --git a/INDICATOR_VERSION_TRACKING.md b/docs/architecture/INDICATOR_VERSION_TRACKING.md
similarity index 100%
rename from INDICATOR_VERSION_TRACKING.md
rename to docs/architecture/INDICATOR_VERSION_TRACKING.md
diff --git a/POSITION_SYNC_QUICK_REF.md b/docs/architecture/POSITION_SYNC_QUICK_REF.md
similarity index 100%
rename from POSITION_SYNC_QUICK_REF.md
rename to docs/architecture/POSITION_SYNC_QUICK_REF.md
diff --git a/VERIFICATION_CHECKLIST_NOV12.md b/docs/archived/2025_pre_nov/VERIFICATION_CHECKLIST_NOV12.md
similarity index 100%
rename from VERIFICATION_CHECKLIST_NOV12.md
rename to docs/archived/2025_pre_nov/VERIFICATION_CHECKLIST_NOV12.md
diff --git a/CRITICAL_FIX_POSITION_SIZE_BUG.md b/docs/bugs/CRITICAL_FIX_POSITION_SIZE_BUG.md
similarity index 100%
rename from CRITICAL_FIX_POSITION_SIZE_BUG.md
rename to docs/bugs/CRITICAL_FIX_POSITION_SIZE_BUG.md
diff --git a/CRITICAL_INCIDENT_UNPROTECTED_POSITION.md b/docs/bugs/CRITICAL_INCIDENT_UNPROTECTED_POSITION.md
similarity index 100%
rename from CRITICAL_INCIDENT_UNPROTECTED_POSITION.md
rename to docs/bugs/CRITICAL_INCIDENT_UNPROTECTED_POSITION.md
diff --git a/CRITICAL_ISSUES_FOUND.md b/docs/bugs/CRITICAL_ISSUES_FOUND.md
similarity index 100%
rename from CRITICAL_ISSUES_FOUND.md
rename to docs/bugs/CRITICAL_ISSUES_FOUND.md
diff --git a/CRITICAL_MISSING_TRADES_NOV19.md b/docs/bugs/CRITICAL_MISSING_TRADES_NOV19.md
similarity index 100%
rename from CRITICAL_MISSING_TRADES_NOV19.md
rename to docs/bugs/CRITICAL_MISSING_TRADES_NOV19.md
diff --git a/CRITICAL_TP1_FALSE_DETECTION_BUG.md b/docs/bugs/CRITICAL_TP1_FALSE_DETECTION_BUG.md
similarity index 100%
rename from CRITICAL_TP1_FALSE_DETECTION_BUG.md
rename to docs/bugs/CRITICAL_TP1_FALSE_DETECTION_BUG.md
diff --git a/FIXES_APPLIED.md b/docs/bugs/FIXES_APPLIED.md
similarity index 100%
rename from FIXES_APPLIED.md
rename to docs/bugs/FIXES_APPLIED.md
diff --git a/FIXES_RUNNER_AND_CANCELLATION.md b/docs/bugs/FIXES_RUNNER_AND_CANCELLATION.md
similarity index 100%
rename from FIXES_RUNNER_AND_CANCELLATION.md
rename to docs/bugs/FIXES_RUNNER_AND_CANCELLATION.md
diff --git a/CLUSTER_START_BUTTON_FIX.md b/docs/cluster/CLUSTER_START_BUTTON_FIX.md
similarity index 100%
rename from CLUSTER_START_BUTTON_FIX.md
rename to docs/cluster/CLUSTER_START_BUTTON_FIX.md
diff --git a/DUAL_SWEEP_README.md b/docs/cluster/DUAL_SWEEP_README.md
similarity index 100%
rename from DUAL_SWEEP_README.md
rename to docs/cluster/DUAL_SWEEP_README.md
diff --git a/EPYC_SETUP_COMPREHENSIVE.md b/docs/cluster/EPYC_SETUP_COMPREHENSIVE.md
similarity index 100%
rename from EPYC_SETUP_COMPREHENSIVE.md
rename to docs/cluster/EPYC_SETUP_COMPREHENSIVE.md
diff --git a/CLUSTER_STOP_BUTTON_FIX_COMPLETE.md b/docs/deployments/CLUSTER_STOP_BUTTON_FIX_COMPLETE.md
similarity index 100%
rename from CLUSTER_STOP_BUTTON_FIX_COMPLETE.md
rename to docs/deployments/CLUSTER_STOP_BUTTON_FIX_COMPLETE.md
diff --git a/docs/deployments/DEPLOYMENT_SUCCESS_DEC3_2025.md b/docs/deployments/DEPLOYMENT_SUCCESS_DEC3_2025.md
new file mode 100644
index 0000000..a201277
--- /dev/null
+++ b/docs/deployments/DEPLOYMENT_SUCCESS_DEC3_2025.md
@@ -0,0 +1,200 @@
+# 🎉 Deployment Success - Bug #1 and Bug #2 Fixes Live
+
+**Date:** December 3, 2025, 09:02 CET
+**Status:** ✅ **BOTH FIXES DEPLOYED AND VERIFIED**
+
+---
+
+## Timeline
+
+### Commits
+- **08:11:24 CET** - Bug #2 committed (58f812f): Direction-specific leverage thresholds
+- **08:16:27 CET** - Bug #1 committed (7d0d38a): Smart Entry signal price fix
+
+### Previous Deployment Attempts
+- **07:16:42 CET** - Container started (old code, fixes not deployed)
+- **08:16:42 CET** - Investigation revealed deployment never happened
+
+### Successful Deployment
+- **09:02:45 CET** - Container rebuilt and restarted **WITH BOTH FIXES** ✅
+
+---
+
+## Verification Evidence
+
+### Container Timestamps
+```bash
+$ docker inspect trading-bot-v4 --format='{{.State.StartedAt}}'
+2025-12-03T09:02:45.478178367Z ✅ AFTER both commits!
+
+$ git log --oneline --since="2025-12-03 08:00"
+7d0d38a 2025-12-03 08:16:27 +0100 ✅ BEFORE container start
+58f812f 2025-12-03 08:11:24 +0100 ✅ BEFORE container start
+```
+
+### Container Status
+```
+trading-bot-v4: Up since 09:02:45 CET
+Status: Healthy
+Processing: Signals received and quality filtering working
+```
+
+### Recent Signal Evidence
+```
+🎯 Trade execution request received
+📊 Signal quality: 45 (BLOCKED)
+```
+System is actively processing signals with quality filtering operational.
+
+---
+
+## What Was Fixed
+
+### Bug #1: Smart Entry Using Wrong Signal Price ✅ DEPLOYED
+**Problem:** Smart Entry used `body.pricePosition` (percentage like 70.8) as signal price instead of actual market price (~$142)
+
+**Impact:**
+- Smart Entry calculated 97% pullbacks (impossible)
+- Triggered "pullback too large - possible reversal" logic
+- Resulted in $89 positions instead of $2,300
+
+**Fix Location:** `app/api/trading/execute/route.ts` (lines 485-565)
+
+**Before:**
+```typescript
+const signalPrice = body.signalPrice // Was pricePosition (70.8)
+```
+
+**After:**
+```typescript
+// Get current market price from Pyth
+const priceMonitor = getPythPriceMonitor()
+const latestPrice = priceMonitor.getCachedPrice(driftSymbol)
+const currentPrice = latestPrice?.price
+const signalPrice = currentPrice // Actual market price (~$142)
+```
+
+---
+
+### Bug #2: Direction-Specific Leverage Thresholds ✅ DEPLOYED
+**Problem:** ENV variables for direction-specific thresholds not explicitly loaded
+
+**Fix Location:** `config/trading.ts` (lines 496-507)
+
+**Added:**
+```typescript
+// Direction-specific quality thresholds (Nov 28, 2025)
+QUALITY_LEVERAGE_THRESHOLD_LONG: parseInt(
+ process.env.QUALITY_LEVERAGE_THRESHOLD_LONG ||
+ process.env.QUALITY_LEVERAGE_THRESHOLD ||
+ '95'
+),
+QUALITY_LEVERAGE_THRESHOLD_SHORT: parseInt(
+ process.env.QUALITY_LEVERAGE_THRESHOLD_SHORT ||
+ process.env.QUALITY_LEVERAGE_THRESHOLD ||
+ '90'
+)
+```
+
+---
+
+## Next Steps
+
+### 1. Wait for Quality 90+ Signal
+Most signals are quality 70-85 (blocked). Need quality 90+ for actual execution.
+
+**Monitor command:**
+```bash
+docker logs -f trading-bot-v4 | grep -E "Signal quality|Opening.*position"
+```
+
+### 2. Verify Position Size in Database
+After next trade executes:
+```bash
+docker exec trading-bot-postgres psql -U postgres -d trading_bot_v4 -c "
+SELECT
+ direction, symbol, \"entryPrice\", \"positionSizeUSD\",
+ leverage, \"signalQualityScore\",
+ TO_CHAR(\"createdAt\", 'MM-DD HH24:MI:SS') as created
+FROM \"Trade\"
+WHERE symbol='SOL-PERP'
+ORDER BY \"createdAt\" DESC
+LIMIT 1;
+"
+```
+
+**Expected:**
+- positionSizeUSD ≈ **$2,300** (not $89!)
+- entryPrice ≈ **$142-145** (current market)
+- leverage = **5x** or **10x** (based on quality)
+
+### 3. Implement Bug #3
+After verification: Add Telegram entry notifications
+
+---
+
+## Deployment Checklist (For Future Reference)
+
+✅ Code committed to git
+✅ Container image rebuilt: `docker compose build trading-bot`
+✅ Container restarted: `docker compose up -d trading-bot`
+✅ Verified container start time > commit time
+✅ Checked logs for signal processing
+⏳ Awaiting quality 90+ signal for full verification
+
+---
+
+## Lessons Learned
+
+### 1. Always Verify Deployment
+**Never assume code is deployed just because it's committed!**
+
+Check sequence:
+1. Commit code to git ✅
+2. **Rebuild container image** ✅
+3. **Restart container** ✅
+4. **Verify timestamps** ✅
+5. **Check logs for new behavior** ⏳
+
+### 2. Container Timestamp Verification
+```bash
+# Get commit time
+git log -1 --format='%ai'
+
+# Get container start time
+docker inspect
--format='{{.State.StartedAt}}'
+
+# Container MUST be newer than commit!
+```
+
+### 3. Deployment ≠ Commit
+- Committing = Saves code to git
+- Deployment = Rebuilding + Restarting container
+- Both are required!
+
+---
+
+## Current Status
+
+### System Health
+- ✅ Container running with fixed code
+- ✅ Quality filtering operational (blocked quality 45 signal)
+- ✅ All services initialized correctly
+- ✅ Ready for next quality 90+ signal
+
+### Waiting For
+Next quality 90+ signal to verify:
+- Signal price is ~$142 (actual market), not ~$70 (percentage)
+- Smart Entry calculates reasonable pullback (<1%, not 97%)
+- Position opens at ~$2,300 notional (not $89)
+- Database shows correct size
+
+### Timeline Estimate
+Quality 90+ signals are less frequent. Could be:
+- Minutes (if market conditions align)
+- Hours (more typical)
+- Next trading session (most likely)
+
+---
+
+**Deployment Status:** ✅ **SUCCESS - FIXES NOW LIVE IN PRODUCTION**
diff --git a/MA_CROSSOVER_DETECTION_COMPLETE.md b/docs/deployments/MA_CROSSOVER_DETECTION_COMPLETE.md
similarity index 100%
rename from MA_CROSSOVER_DETECTION_COMPLETE.md
rename to docs/deployments/MA_CROSSOVER_DETECTION_COMPLETE.md
diff --git a/ONE_YEAR_RETENTION_DEPLOYMENT.md b/docs/deployments/ONE_YEAR_RETENTION_DEPLOYMENT.md
similarity index 100%
rename from ONE_YEAR_RETENTION_DEPLOYMENT.md
rename to docs/deployments/ONE_YEAR_RETENTION_DEPLOYMENT.md
diff --git a/PHASE_4_VERIFICATION_COMPLETE.md b/docs/deployments/PHASE_4_VERIFICATION_COMPLETE.md
similarity index 100%
rename from PHASE_4_VERIFICATION_COMPLETE.md
rename to docs/deployments/PHASE_4_VERIFICATION_COMPLETE.md
diff --git a/PHASE_7.3_ADAPTIVE_TRAILING_DEPLOYED.md b/docs/deployments/PHASE_7.3_ADAPTIVE_TRAILING_DEPLOYED.md
similarity index 100%
rename from PHASE_7.3_ADAPTIVE_TRAILING_DEPLOYED.md
rename to docs/deployments/PHASE_7.3_ADAPTIVE_TRAILING_DEPLOYED.md
diff --git a/REENTRY_SYSTEM_COMPLETE.md b/docs/deployments/REENTRY_SYSTEM_COMPLETE.md
similarity index 100%
rename from REENTRY_SYSTEM_COMPLETE.md
rename to docs/deployments/REENTRY_SYSTEM_COMPLETE.md
diff --git a/RUNNER_SYSTEM_FIX_COMPLETE.md b/docs/deployments/RUNNER_SYSTEM_FIX_COMPLETE.md
similarity index 100%
rename from RUNNER_SYSTEM_FIX_COMPLETE.md
rename to docs/deployments/RUNNER_SYSTEM_FIX_COMPLETE.md
diff --git a/SMART_ENTRY_DEPLOYMENT_STATUS.md b/docs/deployments/SMART_ENTRY_DEPLOYMENT_STATUS.md
similarity index 100%
rename from SMART_ENTRY_DEPLOYMENT_STATUS.md
rename to docs/deployments/SMART_ENTRY_DEPLOYMENT_STATUS.md
diff --git a/SMART_ENTRY_TIMING_STATUS.md b/docs/deployments/SMART_ENTRY_TIMING_STATUS.md
similarity index 100%
rename from SMART_ENTRY_TIMING_STATUS.md
rename to docs/deployments/SMART_ENTRY_TIMING_STATUS.md
diff --git a/TP1_FIX_DEPLOYMENT_SUMMARY.md b/docs/deployments/TP1_FIX_DEPLOYMENT_SUMMARY.md
similarity index 100%
rename from TP1_FIX_DEPLOYMENT_SUMMARY.md
rename to docs/deployments/TP1_FIX_DEPLOYMENT_SUMMARY.md
diff --git a/V9_IMPLEMENTATION_COMPLETE.md b/docs/deployments/V9_IMPLEMENTATION_COMPLETE.md
similarity index 100%
rename from V9_IMPLEMENTATION_COMPLETE.md
rename to docs/deployments/V9_IMPLEMENTATION_COMPLETE.md
diff --git a/1MIN_DATA_ENHANCEMENTS_ROADMAP.md b/docs/roadmaps/1MIN_DATA_ENHANCEMENTS_ROADMAP.md
similarity index 100%
rename from 1MIN_DATA_ENHANCEMENTS_ROADMAP.md
rename to docs/roadmaps/1MIN_DATA_ENHANCEMENTS_ROADMAP.md
diff --git a/ATR_BASED_TP_ROADMAP.md b/docs/roadmaps/ATR_BASED_TP_ROADMAP.md
similarity index 100%
rename from ATR_BASED_TP_ROADMAP.md
rename to docs/roadmaps/ATR_BASED_TP_ROADMAP.md
diff --git a/HA_SETUP_ROADMAP.md b/docs/roadmaps/HA_SETUP_ROADMAP.md
similarity index 100%
rename from HA_SETUP_ROADMAP.md
rename to docs/roadmaps/HA_SETUP_ROADMAP.md
diff --git a/INDICATOR_V9_MA_GAP_ROADMAP.md b/docs/roadmaps/INDICATOR_V9_MA_GAP_ROADMAP.md
similarity index 100%
rename from INDICATOR_V9_MA_GAP_ROADMAP.md
rename to docs/roadmaps/INDICATOR_V9_MA_GAP_ROADMAP.md
diff --git a/OPTIMIZATION_MASTER_ROADMAP.md b/docs/roadmaps/OPTIMIZATION_MASTER_ROADMAP.md
similarity index 100%
rename from OPTIMIZATION_MASTER_ROADMAP.md
rename to docs/roadmaps/OPTIMIZATION_MASTER_ROADMAP.md
diff --git a/POSITION_SCALING_ROADMAP.md b/docs/roadmaps/POSITION_SCALING_ROADMAP.md
similarity index 100%
rename from POSITION_SCALING_ROADMAP.md
rename to docs/roadmaps/POSITION_SCALING_ROADMAP.md
diff --git a/SIGNAL_QUALITY_OPTIMIZATION_ROADMAP.md b/docs/roadmaps/SIGNAL_QUALITY_OPTIMIZATION_ROADMAP.md
similarity index 100%
rename from SIGNAL_QUALITY_OPTIMIZATION_ROADMAP.md
rename to docs/roadmaps/SIGNAL_QUALITY_OPTIMIZATION_ROADMAP.md
diff --git a/MARKETDATA_EXECUTE_ENDPOINT_FIX.md b/docs/setup/MARKETDATA_EXECUTE_ENDPOINT_FIX.md
similarity index 100%
rename from MARKETDATA_EXECUTE_ENDPOINT_FIX.md
rename to docs/setup/MARKETDATA_EXECUTE_ENDPOINT_FIX.md
diff --git a/N8N_MARKET_DATA_SETUP.md b/docs/setup/N8N_MARKET_DATA_SETUP.md
similarity index 100%
rename from N8N_MARKET_DATA_SETUP.md
rename to docs/setup/N8N_MARKET_DATA_SETUP.md
diff --git a/PERCENTAGE_SIZING_FEATURE.md b/docs/setup/PERCENTAGE_SIZING_FEATURE.md
similarity index 100%
rename from PERCENTAGE_SIZING_FEATURE.md
rename to docs/setup/PERCENTAGE_SIZING_FEATURE.md
diff --git a/QUICK_SETUP_CARD.md b/docs/setup/QUICK_SETUP_CARD.md
similarity index 100%
rename from QUICK_SETUP_CARD.md
rename to docs/setup/QUICK_SETUP_CARD.md
diff --git a/SIGNAL_QUALITY_SETUP_GUIDE.md b/docs/setup/SIGNAL_QUALITY_SETUP_GUIDE.md
similarity index 100%
rename from SIGNAL_QUALITY_SETUP_GUIDE.md
rename to docs/setup/SIGNAL_QUALITY_SETUP_GUIDE.md
diff --git a/TRADINGVIEW_EASIEST_METHOD.md b/docs/setup/TRADINGVIEW_EASIEST_METHOD.md
similarity index 100%
rename from TRADINGVIEW_EASIEST_METHOD.md
rename to docs/setup/TRADINGVIEW_EASIEST_METHOD.md
diff --git a/TRADINGVIEW_MARKET_DATA_ALERTS.md b/docs/setup/TRADINGVIEW_MARKET_DATA_ALERTS.md
similarity index 100%
rename from TRADINGVIEW_MARKET_DATA_ALERTS.md
rename to docs/setup/TRADINGVIEW_MARKET_DATA_ALERTS.md
diff --git a/TRADINGVIEW_STEP_BY_STEP.md b/docs/setup/TRADINGVIEW_STEP_BY_STEP.md
similarity index 100%
rename from TRADINGVIEW_STEP_BY_STEP.md
rename to docs/setup/TRADINGVIEW_STEP_BY_STEP.md