all changes done over the last 2 weeks
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
🔧 Fix Indentation Error in Patched Notebook
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
NOTEBOOK_PATH = "TradingBot_V1.6_Adaptive_Complete_CORRECTED.ipynb"
|
||||
|
||||
def fix_notebook():
|
||||
"""Fix the indentation error in execute_trade function"""
|
||||
|
||||
print("=" * 70)
|
||||
print("🔧 FIXING INDENTATION ERROR")
|
||||
print("=" * 70)
|
||||
|
||||
# Load notebook
|
||||
print(f"\n1️⃣ Loading notebook: {NOTEBOOK_PATH}")
|
||||
|
||||
try:
|
||||
with open(NOTEBOOK_PATH, 'r', encoding='utf-8') as f:
|
||||
notebook = json.load(f)
|
||||
except FileNotFoundError:
|
||||
print(f"❌ Error: Notebook not found: {NOTEBOOK_PATH}")
|
||||
return False
|
||||
|
||||
print(f"✅ Loaded {len(notebook['cells'])} cells")
|
||||
|
||||
# Find execute_trade cell
|
||||
print("\n2️⃣ Finding execute_trade cell...")
|
||||
|
||||
execute_cell_index = None
|
||||
for i, cell in enumerate(notebook['cells']):
|
||||
if cell['cell_type'] == 'code':
|
||||
source = ''.join(cell['source'])
|
||||
if 'def execute_trade_v2_adaptive(' in source:
|
||||
execute_cell_index = i
|
||||
print(f"✅ Found at cell {i}")
|
||||
break
|
||||
|
||||
if execute_cell_index is None:
|
||||
print("❌ Error: Could not find execute_trade cell!")
|
||||
return False
|
||||
|
||||
# Get the cell
|
||||
execute_cell = notebook['cells'][execute_cell_index]
|
||||
source_lines = execute_cell['source']
|
||||
|
||||
# Find the problematic section and fix it
|
||||
print("\n3️⃣ Fixing indentation...")
|
||||
|
||||
fixed_lines = []
|
||||
i = 0
|
||||
while i < len(source_lines):
|
||||
line = source_lines[i]
|
||||
|
||||
# Find the adaptive sizing section
|
||||
if "# 🎯 ADAPTIVE POSITION SIZING" in line:
|
||||
# Replace entire section with correct indentation
|
||||
fixed_lines.append(line)
|
||||
i += 1
|
||||
|
||||
# Add correctly indented code
|
||||
fixed_lines.append(" if 'adv_position_mgr' in globals() and adv_position_mgr.adaptive_sizing:\n")
|
||||
fixed_lines.append(" volume = adv_position_mgr.adaptive_sizing.calculate_position_size(\n")
|
||||
fixed_lines.append(" confidence=confidence,\n")
|
||||
fixed_lines.append(" balance=balance,\n")
|
||||
fixed_lines.append(" stop_loss_distance=adjusted_atr_mult * atr * 10000, # Convert to pips\n")
|
||||
fixed_lines.append(" symbol=symbol\n")
|
||||
fixed_lines.append(" )\n")
|
||||
fixed_lines.append(" else:\n")
|
||||
fixed_lines.append(" volume = round(min(0.1, max(0.01, risk_amount / (adjusted_atr_mult * atr * 100))),2)\n")
|
||||
|
||||
# Skip old lines until we find the next non-indented or different section
|
||||
while i < len(source_lines):
|
||||
next_line = source_lines[i]
|
||||
if next_line.strip() and not next_line.startswith(' '):
|
||||
break
|
||||
if 'volume = round(min(0.1' in next_line and 'adaptive' not in source_lines[i-1]:
|
||||
i += 1
|
||||
break
|
||||
i += 1
|
||||
continue
|
||||
|
||||
fixed_lines.append(line)
|
||||
i += 1
|
||||
|
||||
# Update cell
|
||||
execute_cell['source'] = fixed_lines
|
||||
|
||||
print("✅ Indentation fixed")
|
||||
|
||||
# Save
|
||||
print(f"\n4️⃣ Saving fixed notebook...")
|
||||
|
||||
with open(NOTEBOOK_PATH, 'w', encoding='utf-8') as f:
|
||||
json.dump(notebook, f, indent=1, ensure_ascii=False)
|
||||
|
||||
print("✅ Notebook saved!")
|
||||
|
||||
print("\n" + "=" * 70)
|
||||
print("✅ FIX COMPLETE!")
|
||||
print("=" * 70)
|
||||
print("\nNext: Restart Jupyter Kernel and Run All")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = fix_notebook()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user