feat: Trading Bot V1.8 - Aggressive Mode + Infrastructure
## Major Features - Session Filter: NY-only trading (13:00-21:00 UTC) - SQLite Database: Structured trade logging - Telegram Bot: Real-time notifications (@Xausd_digger_bot) - Streamlit Dashboard: Visual monitoring & analytics - JSON Import: Historical data migration ## Infrastructure - trading_database.py: SQLite trade storage - telegram_notifier.py: Telegram integration - infrastructure_patch.py: Combined DB + Telegram - trading_dashboard.py: Real-time web dashboard - import_json_to_db.py: JSON to SQLite migration ## Session Filter (V1.8 Aggressive Mode) - session_filter_patch.py: Whitelist-based filter - Blocks: Asian, London, Overlap sessions - Active: NY session only (best performance: 47.6% WR) - Base confidence: 60% ## Documentation - V1.8_AGGRESSIVE_MODE_AKTIVIERT.md - FIX_DUPLICATE_SCHEDULER.md - DASHBOARD_WINDOWS_SERVER.md - SQLITE_TELEGRAM_SETUP.md - PROJECT_CLEANUP.md ## Cleanup - Archived old V1.1-V1.7 versions - Removed obsolete analysis scripts (replaced by dashboard) - Added .gitignore for secrets and temp files ## Breaking Changes - Requires telegram_config.json (use template) - Requires Python packages: streamlit, plotly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,306 @@
|
||||
# 🔧 FIX: Duplicate Scheduler Problem
|
||||
|
||||
## ❌ Problem Identifiziert
|
||||
|
||||
**Symptom:** Bot tradet während London Session trotz SESSION_WHITELIST_CONFIG mit nur NY aktiviert
|
||||
|
||||
**Root Cause:** **DUPLICATE Scheduler Jobs!**
|
||||
|
||||
Beweis aus deinen Logs:
|
||||
```
|
||||
2025-11-26 11:37:00 - INFO - Running job "create_session_filtered_check..." (scheduled at 11:37:00)
|
||||
2025-11-26 11:37:00 - INFO - ⏸️ Trading SKIP: Session blocked: London
|
||||
2025-11-26 11:37:00 - INFO - Running job "create_session_filtered_check..." (scheduled at 11:37:00)
|
||||
2025-11-26 11:37:00 - INFO - ⏸️ Trading SKIP: Session blocked: London
|
||||
```
|
||||
|
||||
**Was passiert:**
|
||||
1. ✅ **NEUER** Scheduler mit Session Filter → blockiert London korrekt
|
||||
2. ❌ **ALTER** Scheduler OHNE Session Filter → tradet weiter!
|
||||
|
||||
## 🔍 Wie ist das passiert?
|
||||
|
||||
**Szenario:**
|
||||
1. Du hast Cell 33 (Scheduler Start) mehrmals ausgeführt
|
||||
2. Jedes Mal wurde ein NEUER Scheduler erstellt
|
||||
3. ALTE Scheduler laufen weiter im Hintergrund
|
||||
4. Result: 2+ Jobs zur gleichen Zeit!
|
||||
|
||||
## ✅ Lösung: Scheduler Cleanup + Neustart
|
||||
|
||||
### SCHRITT 1: Alle laufenden Scheduler stoppen
|
||||
|
||||
**In einer NEUEN Notebook Cell ausführen:**
|
||||
|
||||
```python
|
||||
# ==========================================
|
||||
# SCHRITT 1: ALLE SCHEDULER STOPPEN
|
||||
# ==========================================
|
||||
|
||||
print("🔄 Stopping all schedulers...")
|
||||
|
||||
# Stop current scheduler
|
||||
try:
|
||||
scheduler.shutdown(wait=False)
|
||||
print("✅ Main scheduler stopped")
|
||||
except:
|
||||
print("⚠️ No main scheduler found")
|
||||
|
||||
# Check for orphaned schedulers
|
||||
import gc
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
|
||||
orphaned_count = 0
|
||||
for obj in gc.get_objects():
|
||||
try:
|
||||
if isinstance(obj, BackgroundScheduler):
|
||||
if obj.running:
|
||||
obj.shutdown(wait=False)
|
||||
orphaned_count += 1
|
||||
print(f"✅ Stopped orphaned scheduler {orphaned_count}")
|
||||
except:
|
||||
pass
|
||||
|
||||
print(f"\n✅ Cleanup complete! Stopped {orphaned_count + 1} scheduler(s)")
|
||||
print("⏸️ Bot is now PAUSED - no trading happening")
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe:**
|
||||
```
|
||||
🔄 Stopping all schedulers...
|
||||
✅ Main scheduler stopped
|
||||
✅ Stopped orphaned scheduler 1
|
||||
✅ Stopped orphaned scheduler 2
|
||||
✅ Cleanup complete! Stopped 3 scheduler(s)
|
||||
```
|
||||
|
||||
### SCHRITT 2: Session Filter Configuration bestätigen
|
||||
|
||||
**Prüfe nochmal die Config:**
|
||||
|
||||
```python
|
||||
# ==========================================
|
||||
# SCHRITT 2: VERIFY SESSION FILTER CONFIG
|
||||
# ==========================================
|
||||
|
||||
from session_filter_patch import SESSION_WHITELIST_CONFIG, is_session_allowed
|
||||
|
||||
print("📊 CURRENT SESSION FILTER CONFIGURATION:")
|
||||
print("=" * 60)
|
||||
|
||||
for session in ['asian', 'london', 'overlap', 'ny']:
|
||||
allowed, reason = is_session_allowed(session)
|
||||
emoji = "✅ AKTIV" if allowed else "❌ BLOCKED"
|
||||
print(f"{emoji:12s} {session.upper():8s}: {reason}")
|
||||
|
||||
print("\n📋 Full Config:")
|
||||
print(f"Enabled Sessions: {SESSION_WHITELIST_CONFIG['enabled_sessions']}")
|
||||
print(f"Base Confidence: {SESSION_WHITELIST_CONFIG['base_confidence']}%")
|
||||
print(f"Aggressive Mode: {SESSION_WHITELIST_CONFIG.get('aggressive_mode', False)}")
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe:**
|
||||
```
|
||||
❌ BLOCKED ASIAN : Session blocked: Asian has -$199 loss...
|
||||
❌ BLOCKED LONDON : Session blocked: London is break-even...
|
||||
❌ BLOCKED OVERLAP : Session blocked: Not in whitelist
|
||||
✅ AKTIV NY : NY allowed: +$372 profit, 50.0% win-rate
|
||||
```
|
||||
|
||||
### SCHRITT 3: Neuen Scheduler mit Session Filter starten
|
||||
|
||||
**Erstelle einen FRISCHEN Scheduler:**
|
||||
|
||||
```python
|
||||
# ==========================================
|
||||
# SCHRITT 3: CREATE FRESH SCHEDULER
|
||||
# ==========================================
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from session_filter_patch import create_session_filtered_check, SESSION_WHITELIST_CONFIG
|
||||
from infrastructure_patch import create_scheduled_reports
|
||||
|
||||
print("🚀 Creating FRESH scheduler with session filter...")
|
||||
|
||||
# Create NEW scheduler instance
|
||||
scheduler = BackgroundScheduler()
|
||||
|
||||
# Create session-filtered trading check
|
||||
adaptive_trading_check = create_session_filtered_check(
|
||||
rhythm_manager=rhythm_manager,
|
||||
execute_func=execute_trade_v2_adaptive,
|
||||
symbol=symbol,
|
||||
strategy_name=strategy_name,
|
||||
max_positions=max_positions,
|
||||
logger=logger,
|
||||
datetime=datetime,
|
||||
config=SESSION_WHITELIST_CONFIG # ✅ EXPLICITLY pass config
|
||||
)
|
||||
|
||||
# Add FILTERED trading job
|
||||
scheduler.add_job(
|
||||
func=adaptive_trading_check,
|
||||
trigger='cron',
|
||||
minute='*',
|
||||
id='adaptive_trading_check_v18', # NEW ID to avoid conflicts
|
||||
replace_existing=True
|
||||
)
|
||||
|
||||
# Add status report
|
||||
scheduler.add_job(
|
||||
func=print_status_report,
|
||||
trigger='cron',
|
||||
minute='0,30',
|
||||
id='status_report_v18',
|
||||
replace_existing=True
|
||||
)
|
||||
|
||||
# Add infrastructure reports
|
||||
create_scheduled_reports(infra, scheduler)
|
||||
|
||||
# Start scheduler
|
||||
scheduler.start()
|
||||
|
||||
print("\n✅ FRESH SCHEDULER STARTED!")
|
||||
print(f" Active Jobs: {len(scheduler.get_jobs())}")
|
||||
print("\n📋 Scheduled Jobs:")
|
||||
for job in scheduler.get_jobs():
|
||||
print(f" • {job.id} - {job.trigger}")
|
||||
|
||||
print("\n⚠️ SESSION FILTER ACTIVE:")
|
||||
for session, enabled in SESSION_WHITELIST_CONFIG['enabled_sessions'].items():
|
||||
status = "✅ TRADING" if enabled else "❌ BLOCKED"
|
||||
print(f" {session.upper():8s}: {status}")
|
||||
|
||||
print("\n🎯 Bot will ONLY trade during NY session (13:00-21:00 UTC)")
|
||||
print("🔒 All other sessions are BLOCKED")
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe:**
|
||||
```
|
||||
✅ FRESH SCHEDULER STARTED!
|
||||
Active Jobs: 4
|
||||
|
||||
📋 Scheduled Jobs:
|
||||
• adaptive_trading_check_v18 - cron[minute='*']
|
||||
• status_report_v18 - cron[minute='0,30']
|
||||
• daily_report - cron[hour='22', minute='0']
|
||||
• weekly_report - cron[day_of_week='sun', hour='23', minute='0']
|
||||
|
||||
⚠️ SESSION FILTER ACTIVE:
|
||||
ASIAN : ❌ BLOCKED
|
||||
LONDON : ❌ BLOCKED
|
||||
OVERLAP : ❌ BLOCKED
|
||||
NY : ✅ TRADING
|
||||
```
|
||||
|
||||
### SCHRITT 4: Verification Test
|
||||
|
||||
**Warte 1-2 Minuten und prüfe die Logs:**
|
||||
|
||||
```python
|
||||
# ==========================================
|
||||
# SCHRITT 4: VERIFY LOGS
|
||||
# ==========================================
|
||||
|
||||
import time
|
||||
print("⏰ Waiting 90 seconds to collect logs...")
|
||||
time.sleep(90)
|
||||
|
||||
print("\n📊 Last few log entries should show:")
|
||||
print(" ⏸️ Trading SKIP: Session blocked: London")
|
||||
print("\n✅ If you see this → Session filter is working!")
|
||||
```
|
||||
|
||||
## 📊 Expected Behavior nach Fix
|
||||
|
||||
### Während London Session (08:00-13:00 UTC / 09:00-14:00 CET):
|
||||
```
|
||||
2025-11-26 11:37:00 - INFO - ⏸️ Trading SKIP: Session blocked: London
|
||||
2025-11-26 11:38:00 - INFO - ⏸️ Trading SKIP: Session blocked: London
|
||||
2025-11-26 11:39:00 - INFO - ⏸️ Trading SKIP: Session blocked: London
|
||||
```
|
||||
|
||||
**WICHTIG:** Nur EINE Log-Zeile pro Minute! (Nicht 2 wie vorher)
|
||||
|
||||
### Während NY Session (13:00-21:00 UTC / 14:00-22:00 CET):
|
||||
```
|
||||
2025-11-26 14:00:00 - INFO - ✅ Session: NY - NY allowed: +$372 profit
|
||||
2025-11-26 14:00:00 - INFO - 📊 Confidence Threshold: 60%
|
||||
[Normal trading analysis...]
|
||||
```
|
||||
|
||||
### Andere Sessions:
|
||||
- **Asian (00:00-08:00 UTC):** ⏸️ Trading SKIP
|
||||
- **Overlap (13:00-16:00 UTC):** ⏸️ Trading SKIP (auch wenn in NY Zeit!)
|
||||
|
||||
## 🔍 How to Monitor
|
||||
|
||||
### Quick Check jede Stunde:
|
||||
|
||||
```python
|
||||
# Check current session & status
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
|
||||
now_utc = datetime.now(pytz.UTC)
|
||||
current_session = rhythm_manager.get_current_session()
|
||||
allowed, reason = is_session_allowed(current_session)
|
||||
|
||||
print(f"Time: {now_utc.strftime('%H:%M UTC')}")
|
||||
print(f"Session: {current_session.upper()}")
|
||||
print(f"Trading: {'✅ ACTIVE' if allowed else '❌ BLOCKED'}")
|
||||
print(f"Reason: {reason}")
|
||||
```
|
||||
|
||||
### Full Status:
|
||||
|
||||
```python
|
||||
check_adaptive_bot_status()
|
||||
```
|
||||
|
||||
## ⚠️ WICHTIG: Prevent Future Duplicates
|
||||
|
||||
**NIEMALS nochmal Cell 33 ausführen!**
|
||||
|
||||
Wenn du den Scheduler neu starten musst:
|
||||
|
||||
1. **ERST:** `scheduler.shutdown()` ausführen
|
||||
2. **DANN:** Neue Scheduler Cell ausführen
|
||||
|
||||
**ODER:** Kernel → Restart & Run All (safest!)
|
||||
|
||||
## 🎯 Summary
|
||||
|
||||
**Problem:**
|
||||
- Duplicate schedulers (mit/ohne Session Filter)
|
||||
|
||||
**Lösung:**
|
||||
1. ✅ Alle Scheduler stoppen
|
||||
2. ✅ Config verifizieren
|
||||
3. ✅ Frischen Scheduler mit Session Filter starten
|
||||
4. ✅ Logs monitoren
|
||||
|
||||
**Result:**
|
||||
- Nur 1 Scheduler läuft
|
||||
- Session Filter aktiv
|
||||
- Nur NY Session tradet
|
||||
- London/Asian/Overlap blockiert
|
||||
|
||||
**Expected Log:**
|
||||
```
|
||||
⏸️ Trading SKIP: Session blocked: London ← RICHTIG!
|
||||
(nur EINE Zeile pro Minute während London)
|
||||
```
|
||||
|
||||
## 📱 Next Steps
|
||||
|
||||
Nach dem Fix:
|
||||
|
||||
1. **Monitor 24h:** Prüfe dass KEIN Trade außerhalb NY passiert
|
||||
2. **Check Telegram:** Du solltest jetzt NUR NY-Trades sehen
|
||||
3. **Database Check:** Alle neuen Trades sollten `session='ny'` haben
|
||||
|
||||
**Falls weiterhin London Trades:**
|
||||
→ Kernel Restart erforderlich
|
||||
→ Alle Cells neu ausführen (Kernel → Restart & Run All)
|
||||
Reference in New Issue
Block a user