-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_credentials.py
More file actions
170 lines (132 loc) Β· 5.18 KB
/
test_credentials.py
File metadata and controls
170 lines (132 loc) Β· 5.18 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
#!/usr/bin/env python3
"""
Simple credential test without external dependencies.
"""
import sys
from pathlib import Path
# Add the project root to Python path
sys.path.insert(0, str(Path(__file__).parent))
def test_credentials():
"""Test credential loading without external dependencies."""
print("π Testing Credential Management...")
try:
# Test basic imports first
from crypto_trading_bot.utils.config import ConfigManager
print("β
ConfigManager imported successfully")
# Create config manager
config_manager = ConfigManager()
print("β
ConfigManager created")
# Try to load credentials
try:
api_key, api_secret = config_manager.get_api_credentials()
# Don't print the actual credentials for security
if api_key and api_secret:
print(f"β
Credentials loaded successfully")
print(f" API Key length: {len(api_key)} characters")
print(f" API Secret length: {len(api_secret)} characters")
print(f" API Key starts with: {api_key[:8]}...")
return True
else:
print("β Credentials are empty")
return False
except FileNotFoundError:
print("β Credentials file not found")
print(" You need to set up your credentials first")
return False
except Exception as e:
print(f"β Failed to load credentials: {e}")
return False
except ImportError as e:
print(f"β Import error: {e}")
return False
except Exception as e:
print(f"β Test failed: {e}")
return False
def test_config():
"""Test configuration loading."""
print("\nβοΈ Testing Configuration...")
try:
from crypto_trading_bot.utils.config import ConfigManager
config_manager = ConfigManager()
config = config_manager.load_config()
print(f"β
Configuration loaded with {len(config)} settings")
print(f" Testnet mode: {config.get('testnet', 'Not set')}")
print(f" Symbols: {config.get('symbols', 'Not set')}")
print(f" Strategies: {list(config.get('strategies', {}).keys())}")
return True
except Exception as e:
print(f"β Configuration test failed: {e}")
return False
def setup_credentials_interactive():
"""Interactive credential setup."""
print("\nπ§ Setting up credentials...")
print("Please enter your Binance API credentials:")
api_key = input("API Key: ").strip()
if not api_key:
print("β API Key cannot be empty")
return False
api_secret = input("API Secret: ").strip()
if not api_secret:
print("β API Secret cannot be empty")
return False
try:
from crypto_trading_bot.utils.config import ConfigManager
config_manager = ConfigManager()
# Load existing config
config = config_manager.load_config()
# Add credentials
config['api_key'] = api_key
config['api_secret'] = api_secret
config['testnet'] = True # Always use testnet for safety
# Save config
success = config_manager.save_config(config)
if success:
print("β
Credentials saved successfully!")
return True
else:
print("β Failed to save credentials")
return False
except Exception as e:
print(f"β Setup failed: {e}")
return False
def main():
"""Main function."""
print("π Crypto Trading Bot - Credential Test\n")
# Test if credentials already exist
cred_test = test_credentials()
config_test = test_config()
if not cred_test:
print("\n" + "="*50)
print("Credentials not found or invalid.")
print("Let's set them up now!")
print("="*50)
setup_success = setup_credentials_interactive()
if setup_success:
print("\nβ
Setup complete! Testing again...")
cred_test = test_credentials()
config_test = test_config()
print(f"\nπ Results:")
print(f" Credentials: {'β
Working' if cred_test else 'β Failed'}")
print(f" Configuration: {'β
Working' if config_test else 'β Failed'}")
if cred_test and config_test:
print("\nπ Everything is working!")
print("\nπ Next Steps:")
print(" 1. Install dependencies: pip install aiohttp websockets")
print(" 2. Run: py test_binance_api.py")
print(" 3. Continue with bot development")
return True
else:
print("\nβ οΈ Some issues need to be resolved.")
return False
if __name__ == "__main__":
try:
success = main()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\nβΉοΈ Interrupted by user")
sys.exit(1)
except Exception as e:
print(f"\nπ₯ Test crashed: {e}")
import traceback
traceback.print_exc()
sys.exit(1)