-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_program.py
More file actions
259 lines (209 loc) · 7.62 KB
/
Copy pathverify_program.py
File metadata and controls
259 lines (209 loc) · 7.62 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env python3
"""Comprehensive verification script for the trading bot."""
import sys
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
if PROJECT_ROOT not in sys.path:
sys.path.insert(0, PROJECT_ROOT)
def check_imports():
"""Verify all critical imports work."""
print("=" * 60)
print("1. CHECKING IMPORTS")
print("=" * 60)
try:
from src.broker import BrokerClient
print("✓ BrokerClient")
except Exception as e:
print(f"✗ BrokerClient: {e}")
return False
try:
from src.data import MarketDataClient
print("✓ MarketDataClient")
except Exception as e:
print(f"✗ MarketDataClient: {e}")
return False
try:
from src.risk import RiskManager
print("✓ RiskManager")
except Exception as e:
print(f"✗ RiskManager: {e}")
return False
try:
from src.utils.trade_logger import TradeLogger
print("✓ TradeLogger")
except Exception as e:
print(f"✗ TradeLogger: {e}")
return False
try:
from src.strategy import MultiTimeframeConfluenceStrategy
print("✓ MultiTimeframeConfluenceStrategy")
except Exception as e:
print(f"✗ MultiTimeframeConfluenceStrategy: {e}")
return False
try:
from src.engine import TradingEngine
print("✓ TradingEngine")
except Exception as e:
print(f"✗ TradingEngine: {e}")
return False
try:
from src.indicators import IndicatorEngine
print("✓ IndicatorEngine")
except Exception as e:
print(f"✗ IndicatorEngine: {e}")
return False
try:
from src.strategy.trend_bias_engine import TrendBiasEngine
print("✓ TrendBiasEngine")
except Exception as e:
print(f"✗ TrendBiasEngine: {e}")
return False
try:
import src.config as config
print("✓ Config module")
except Exception as e:
print(f"✗ Config: {e}")
return False
return True
def check_initialization():
"""Verify all components can be initialized."""
print("\n" + "=" * 60)
print("2. CHECKING INITIALIZATION")
print("=" * 60)
try:
from src.strategy import MultiTimeframeConfluenceStrategy
from src.engine import TradingEngine
strategy = MultiTimeframeConfluenceStrategy()
print("✓ Strategy initialized")
engine = TradingEngine(strategy)
print("✓ TradingEngine initialized")
return True
except Exception as e:
print(f"✗ Initialization failed: {e}")
import traceback
traceback.print_exc()
return False
def check_config():
"""Verify critical config values."""
print("\n" + "=" * 60)
print("3. CHECKING CONFIGURATION")
print("=" * 60)
try:
import src.config as config
checks = [
("EXECUTE_TRADES", config.EXECUTE_TRADES, False, "Should be False for safety"),
("WATCHLIST", len(config.WATCHLIST) > 0, True, "Should have symbols"),
("MAX_POSITIONS", config.MAX_POSITIONS, 3, "Should be 3"),
("STOP_LOSS_PCT", config.STOP_LOSS_PCT, 0.02, "Should be 0.02"),
("TAKE_PROFIT_PCT", config.TAKE_PROFIT_PCT, 0.04, "Should be 0.04"),
("BULLISH_SCORE_THRESHOLD", config.BULLISH_SCORE_THRESHOLD, 2.5, "Should be 2.5"),
("BEARISH_SCORE_THRESHOLD", config.BEARISH_SCORE_THRESHOLD, 2.5, "Should be 2.5"),
]
all_ok = True
for name, value, expected, note in checks:
if isinstance(expected, bool):
status = "✓" if value == expected else "✗"
print(f"{status} {name}: {value} ({note})")
if value != expected:
all_ok = False
else:
status = "✓" if abs(value - expected) < 0.001 else "✗"
print(f"{status} {name}: {value} (expected {expected})")
if abs(value - expected) >= 0.001:
all_ok = False
return all_ok
except Exception as e:
print(f"✗ Config check failed: {e}")
return False
def check_trailing_stop():
"""Verify trailing stop logic."""
print("\n" + "=" * 60)
print("4. CHECKING TRAILING STOP")
print("=" * 60)
try:
from src.risk import RiskManager
import src.config as config
risk_mgr = RiskManager()
# Test basic trailing stop computation
stop_pct = risk_mgr.compute_dynamic_stop_pct(
symbol="TEST",
entry_price=100.0,
current_price=102.0,
pnl_pct=0.02,
)
print(f"✓ Trailing stop computation works (test: +2% profit → stop={stop_pct:.2%})")
# Test monotonicity
risk_mgr2 = RiskManager()
stop1 = risk_mgr2.compute_dynamic_stop_pct("TEST2", 100.0, 103.0, 0.03)
stop2 = risk_mgr2.compute_dynamic_stop_pct("TEST2", 100.0, 102.0, 0.02)
if stop2 >= stop1:
print("✓ Monotonicity works (stop doesn't decrease)")
else:
print(f"✗ Monotonicity failed: stop decreased from {stop1:.2%} to {stop2:.2%}")
return False
return True
except Exception as e:
print(f"✗ Trailing stop check failed: {e}")
import traceback
traceback.print_exc()
return False
def check_file_structure():
"""Verify critical files exist."""
print("\n" + "=" * 60)
print("5. CHECKING FILE STRUCTURE")
print("=" * 60)
required_files = [
"main.py",
"src/config.py",
"src/engine/event_loop.py",
"src/strategy/multi_tf_confluence_strategy.py",
"src/risk/risk_manager.py",
"src/data/market_data_client.py",
"src/broker/alpaca_client.py",
"src/utils/trade_logger.py",
"docs/LOGIC_OVERVIEW.md",
]
all_ok = True
for file_path in required_files:
full_path = os.path.join(PROJECT_ROOT, file_path)
if os.path.exists(full_path):
print(f"✓ {file_path}")
else:
print(f"✗ {file_path} - MISSING")
all_ok = False
return all_ok
def main():
"""Run all verification checks."""
print("\n" + "=" * 60)
print("TRADING BOT VERIFICATION")
print("=" * 60)
print()
results = []
results.append(("Imports", check_imports()))
results.append(("Initialization", check_initialization()))
results.append(("Configuration", check_config()))
results.append(("Trailing Stop", check_trailing_stop()))
results.append(("File Structure", check_file_structure()))
print("\n" + "=" * 60)
print("VERIFICATION SUMMARY")
print("=" * 60)
all_passed = True
for name, passed in results:
status = "✓ PASS" if passed else "✗ FAIL"
print(f"{status}: {name}")
if not passed:
all_passed = False
print("=" * 60)
if all_passed:
print("\n✅ ALL CHECKS PASSED - Program appears to be working correctly!")
print("\nNote: This verification does not test:")
print(" - API connectivity (requires .env with valid keys)")
print(" - Actual market data fetching")
print(" - Live trading execution")
print("\nFor full testing, run unit tests: python3 -m unittest discover tests")
return 0
else:
print("\n❌ SOME CHECKS FAILED - Please review the errors above")
return 1
if __name__ == "__main__":
sys.exit(main())