-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
148 lines (117 loc) · 4.32 KB
/
Copy pathtest_setup.py
File metadata and controls
148 lines (117 loc) · 4.32 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
import os
import sys
import json
from dotenv import load_dotenv
load_dotenv()
REQUIRED_KEYS = ["GROQ_API_KEY", "PRISM_API_KEY", "KRAKEN_API_KEY", "KRAKEN_API_SECRET"]
def test_imports():
try:
from market_data import get_market_summary
from ai_brain import analyze_market
from risk_manager import RiskManager
from logger import log_decision, print_banner, print_session_summary
from executor import execute_trade
from config import WATCHLIST, INTERVAL_MINUTES, MAX_TRADES_PER_DAY, MIN_CONFIDENCE, MAX_LOSS_PERCENT, PAPER_MODE
print("[PASS] All modules imported successfully")
return True
except ImportError as e:
print(f"[FAIL] Import error: {e}")
return False
def test_env_file():
env_path = os.path.join(os.path.dirname(__file__), ".env")
if not os.path.exists(env_path):
print("[FAIL] .env file not found - copy .env.example to .env")
return False
missing = [key for key in REQUIRED_KEYS if not os.getenv(key)]
if missing:
print(f"[FAIL] Missing env keys: {', '.join(missing)}")
return False
print("[PASS] .env file exists with all required keys")
return True
def test_market_data():
try:
from market_data import get_market_summary
data = get_market_summary("BTC")
if data is not None and "price" in data:
print(f"[PASS] Market data fetched for BTC")
return True
print("[INFO] Market data returned None (API may not be configured)")
return True
except Exception as e:
print(f"[INFO] Market data test: {e}")
return True
def test_ai_brain():
try:
from ai_brain import analyze_market
fake_data = {"symbol": "BTC", "price": {"price": 65000}, "signals": {"signal": "bullish"}}
result = analyze_market(fake_data)
if "action" in result and "confidence" in result:
print(f"[PASS] AI brain returned valid decision: {result['action']} ({result['confidence']}%)")
return True
print(f"[FAIL] AI brain returned invalid format: {result}")
return False
except Exception as e:
print(f"[INFO] AI brain test: {e}")
return True
def test_logger():
try:
from logger import log_decision
test_decision = {"action": "HOLD", "confidence": 50, "reason": "Test"}
test_data = {"symbol": "BTC", "price": {"price": 50000}, "signals": {}}
log_decision("BTC", test_data, test_decision, False)
if os.path.exists("trade_log.txt"):
print("[PASS] Logger created trade_log.txt")
return True
print("[FAIL] Logger failed to create trade_log.txt")
return False
except Exception as e:
print(f"[FAIL] Logger error: {e}")
return False
def test_executor():
try:
from executor import execute_trade
from config import PAPER_MODE
result = execute_trade("BUY", "BTC")
if result and result.get("status") in ["paper", "success", "error"]:
print(f"[PASS] Executor works in {'PAPER' if PAPER_MODE else 'LIVE'} mode")
return True
print("[FAIL] Executor returned unexpected result")
return False
except Exception as e:
print(f"[FAIL] Executor error: {e}")
return False
def main():
print("=" * 50)
print(" Crypto Trading Agent - Setup Test")
print("=" * 50)
print()
results = []
print("1. Testing module imports...")
results.append(test_imports())
print()
print("2. Testing .env configuration...")
results.append(test_env_file())
print()
print("3. Testing market data fetch...")
results.append(test_market_data())
print()
print("4. Testing AI brain...")
results.append(test_ai_brain())
print()
print("5. Testing logger...")
results.append(test_logger())
print()
print("6. Testing executor...")
results.append(test_executor())
print()
passed = sum(results)
total = len(results)
print("=" * 50)
print(f"RESULTS: {passed}/{total} tests passed")
if passed == total:
print("All tests passed! Ready to run agent.py")
else:
print("Some tests failed. Check configuration.")
print("=" * 50)
if __name__ == "__main__":
main()