Files
Place-Order-Trading-Bot/fix_scheduler_conflict.py
T

67 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""
Quick Fix: Scheduler ConflictingIdError
Fügt replace_existing=True zu allen scheduler.add_job() Calls hinzu
"""
import json
import sys
NOTEBOOK_PATH = "TradingBot_V1.6_Adaptive_Complete_CORRECTED.ipynb"
def fix_scheduler_conflicts():
print("🔧 Fixing Scheduler ConflictingIdError...")
with open(NOTEBOOK_PATH, 'r', encoding='utf-8') as f:
nb = json.load(f)
# Find all scheduler cells
fixed_count = 0
for i, cell in enumerate(nb['cells']):
if cell['cell_type'] == 'code':
source = ''.join(cell['source'])
# Check if this cell has scheduler.add_job without replace_existing
if 'scheduler.add_job' in source and 'replace_existing' not in source:
print(f" Cell {i}: Adding replace_existing=True")
# Replace all scheduler.add_job calls
lines = cell['source']
new_lines = []
in_add_job = False
for line in lines:
if 'scheduler.add_job(' in line:
in_add_job = True
new_lines.append(line)
# If we're in add_job and find the id= parameter, add replace_existing after it
if in_add_job and "id=" in line and "replace_existing" not in line:
# Get indentation from current line
indent = len(line) - len(line.lstrip())
# Add replace_existing=True on next line
new_lines.append(" " * indent + "replace_existing=True,\n")
if in_add_job and ')' in line and 'scheduler.add_job' not in line:
in_add_job = False
cell['source'] = new_lines
fixed_count += 1
if fixed_count > 0:
# Save
with open(NOTEBOOK_PATH, 'w', encoding='utf-8') as f:
json.dump(nb, f, indent=1, ensure_ascii=False)
print(f"✅ Fixed {fixed_count} scheduler calls")
print("\nNext: Restart Jupyter Kernel")
return True
else:
print("⚠️ No scheduler conflicts found to fix")
return False
if __name__ == "__main__":
success = fix_scheduler_conflicts()
sys.exit(0 if success else 1)