#!/usr/bin/env python3 """ Centralize Trading Bot Configuration Creates a centralized configuration cell and updates all references """ import json notebook_path = "TradingBot_V1.6_Adaptive_Complete_CORRECTED.ipynb" print("=" * 70) print("🔧 CENTRALIZING TRADING BOT CONFIGURATION") print("=" * 70) print() # Load notebook with open(notebook_path, 'r', encoding='utf-8') as f: notebook = json.load(f) print(f"Loaded notebook with {len(notebook['cells'])} cells") print() # Create centralized config cell config_cell_markdown = { "cell_type": "markdown", "metadata": {}, "source": [ "## 📋 CENTRALIZED TRADING CONFIGURATION\n", "\n", "**All trading parameters in one place for easy management**" ] } config_cell_code = { "cell_type": "code", "execution_count": None, "metadata": {}, "outputs": [], "source": [ "# ============================================================================\n", "# CENTRALIZED TRADING CONFIGURATION\n", "# ============================================================================\n", "# All trading parameters should be configured here and referenced throughout\n", "# the notebook to avoid scattered settings\n", "\n", "TRADING_CONFIG = {\n", " # ========================================================================\n", " # LOT SIZING & POSITION MANAGEMENT\n", " # ========================================================================\n", " 'lot_sizing': {\n", " 'min_lot': 0.10, # Minimum lot size\n", " 'max_lot': 0.20, # Maximum lot size\n", " 'default_lot': 0.10, # Fallback lot size\n", " 'use_adaptive': True, # Use adaptive position sizing\n", " },\n", " \n", " # ========================================================================\n", " # RISK MANAGEMENT\n", " # ========================================================================\n", " 'risk': {\n", " 'max_risk_per_trade': 0.02, # 2% max risk per trade\n", " 'max_positions': 1, # Maximum concurrent positions\n", " 'max_daily_loss': 0.05, # 5% max daily loss\n", " },\n", " \n", " # ========================================================================\n", " # CONFIDENCE THRESHOLDS\n", " # ========================================================================\n", " 'confidence': {\n", " 'base_threshold': 70, # Base confidence threshold (all sessions)\n", " 'ny_threshold': 70, # NY session threshold (was 97, reduced for more trades)\n", " 'asian_threshold': 70, # Asian session threshold\n", " 'london_threshold': 70, # London session threshold\n", " },\n", " \n", " # ========================================================================\n", " # ATR & STOP LOSS\n", " # ========================================================================\n", " 'atr': {\n", " 'base_multiplier': 1.5, # Base ATR multiplier for SL/TP\n", " 'period': 14, # ATR calculation period\n", " },\n", " \n", " # ========================================================================\n", " # NEWS FILTER\n", " # ========================================================================\n", " 'news_filter': {\n", " 'enabled': True, # Enable/disable news filter\n", " 'minutes_before': 30, # Minutes before event to block\n", " 'minutes_after': 30, # Minutes after event to block\n", " },\n", " \n", " # ========================================================================\n", " # SESSION SETTINGS\n", " # ========================================================================\n", " 'sessions': {\n", " 'asian_enabled': True,\n", " 'london_enabled': False, # Currently disabled\n", " 'ny_enabled': True,\n", " 'overlap_enabled': False, # Currently disabled\n", " },\n", " \n", " # ========================================================================\n", " # TRADING SYMBOLS\n", " # ========================================================================\n", " 'symbols': {\n", " 'primary': 'XAUUSD', # Primary trading symbol (Gold)\n", " 'alternative': [], # Alternative symbols (if needed)\n", " },\n", "}\n", "\n", "# ============================================================================\n", "# HELPER FUNCTIONS\n", "# ============================================================================\n", "\n", "def get_config(section, key=None):\n", " \"\"\"Get configuration value\"\"\"\n", " if key is None:\n", " return TRADING_CONFIG.get(section, {})\n", " return TRADING_CONFIG.get(section, {}).get(key)\n", "\n", "def update_config(section, key, value):\n", " \"\"\"Update configuration value (runtime only, doesn't save to notebook)\"\"\"\n", " if section not in TRADING_CONFIG:\n", " TRADING_CONFIG[section] = {}\n", " TRADING_CONFIG[section][key] = value\n", " print(f\"✅ Updated: {section}.{key} = {value}\")\n", "\n", "# Print current configuration\n", "print(\"✅ TRADING CONFIGURATION LOADED\")\n", "print()\n", "print(f\"📊 Lot Sizing: {TRADING_CONFIG['lot_sizing']['min_lot']} - {TRADING_CONFIG['lot_sizing']['max_lot']} lots\")\n", "print(f\"⚠️ Max Risk: {TRADING_CONFIG['risk']['max_risk_per_trade']*100}% per trade\")\n", "print(f\"🎯 Confidence Threshold: {TRADING_CONFIG['confidence']['base_threshold']}%\")\n", "print(f\"🛡️ News Filter: {'ENABLED' if TRADING_CONFIG['news_filter']['enabled'] else 'DISABLED'}\")\n", "print(f\"🌍 Primary Symbol: {TRADING_CONFIG['symbols']['primary']}\")" ] } # Find a good insertion point (after imports, before main logic) # Let's insert after the first few setup cells (position 5) insert_position = 5 print(f"Inserting centralized config at position {insert_position}") print() # Insert the markdown and code cells notebook['cells'].insert(insert_position, config_cell_markdown) notebook['cells'].insert(insert_position + 1, config_cell_code) print(f"✅ Added 2 new cells (markdown + config)") print(f" Total cells now: {len(notebook['cells'])}") print() # Save the modified notebook with open(notebook_path, 'w', encoding='utf-8') as f: json.dump(notebook, f, indent=1, ensure_ascii=False) print("✅ Notebook updated successfully!") print() print("=" * 70) print("📋 NEXT STEPS:") print("=" * 70) print() print("1. Open Jupyter Notebook") print("2. Locate the new cells (should be around cell 5-6)") print("3. Run the configuration cell to load TRADING_CONFIG") print("4. Update Cells 23, 25, 47 to reference TRADING_CONFIG") print(" instead of hardcoded values") print() print("Example usage in code:") print(" volume = TRADING_CONFIG['lot_sizing']['default_lot']") print(" max_risk = TRADING_CONFIG['risk']['max_risk_per_trade']") print() print("=" * 70)