-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug_main_bot.py
More file actions
99 lines (81 loc) · 3.86 KB
/
debug_main_bot.py
File metadata and controls
99 lines (81 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""
Debug the main bot execution to understand why trades aren't completing
"""
import logging
import time
import pandas as pd
import numpy as np
from trading.execution.binance_executor import BinanceExecutor
from trading.strategies.ensemble_strategy import EnsembleStrategy
def debug_main_bot():
"""Debug the main bot execution flow"""
# Setup logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
logger.info("=== DEBUGGING MAIN BOT EXECUTION ===")
# Step 1: Initialize executor (same as main bot)
logger.info("1. Initializing BinanceExecutor...")
executor = BinanceExecutor(logger=logger, is_testnet=True)
executor.initialize()
# Step 2: Initialize strategy (same as main bot)
logger.info("2. Initializing EnsembleStrategy...")
strategy = EnsembleStrategy(logger=logger)
# Step 3: Create market data (same as main bot mock data)
logger.info("3. Creating market data...")
np.random.seed(42)
mock_data = {
'open': np.random.normal(97000, 200, 50),
'high': np.random.normal(97200, 200, 50),
'low': np.random.normal(96800, 200, 50),
'close': np.random.normal(97000, 200, 50),
'volume': np.random.normal(1000, 100, 50),
}
data = pd.DataFrame(mock_data)
# Add technical indicators (same as main bot)
data['rsi'] = 35 # Oversold - should trigger BUY
data['macd'] = 5.0
data['signal_line'] = 2.0 # MACD > signal - should trigger BUY
data['sma_20'] = 96900
data['adx'] = 40
data['atr'] = 100
logger.info(f"Data shape: {data.shape}, Close price: {data.iloc[-1]['close']:.2f}")
# Step 4: Generate signals (same as main bot)
logger.info("4. Generating signals...")
signals = strategy.generate_signals({"BTCUSDT": data})
logger.info(f"Generated signals: {signals}")
# Step 5: Process signals (same as main bot)
logger.info("5. Processing signals...")
for symbol, signal_info in signals.items():
signal = signal_info.get('signal', 'HOLD')
confidence = signal_info.get('confidence', 0.0)
logger.info(f"Signal: {signal}, Confidence: {confidence}")
if signal in ['BUY', 'SELL'] and confidence > 0.1:
current_price = data.iloc[-1]['close']
available_balance = executor.get_account_balance()
# Calculate position size (same as main bot)
position_size = strategy.calculate_position_size(data, current_price, available_balance)
logger.info(f"Executing {signal} order - Price: ${current_price:.2f}, Size: {position_size:.6f}")
# Execute trade (same as main bot)
if signal == 'BUY':
logger.info("Calling executor.place_order for BUY...")
order_result = executor.place_order(symbol, 'buy', position_size, current_price)
logger.info(f"Order result: {order_result}")
if order_result:
logger.info(f"✅ BUY order executed successfully")
else:
logger.error(f"❌ Failed to execute BUY order")
elif signal == 'SELL':
logger.info("Calling executor.place_order for SELL...")
order_result = executor.place_order(symbol, 'sell', position_size, current_price)
logger.info(f"Order result: {order_result}")
if order_result:
logger.info(f"✅ SELL order executed successfully")
else:
logger.error(f"❌ Failed to execute SELL order")
else:
logger.info(f"No trade executed - conditions not met")
logger.info("=== DEBUGGING COMPLETE ===")
return True
if __name__ == "__main__":
debug_main_bot()