-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_bot.py
More file actions
219 lines (177 loc) Β· 6 KB
/
setup_bot.py
File metadata and controls
219 lines (177 loc) Β· 6 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
#!/usr/bin/env python3
"""
Automated Bot Setup Script
Sets up the entire trading bot system automatically
"""
import os
import sys
import json
import subprocess
from pathlib import Path
def print_header():
print("π CRYPTO TRADING BOT - AUTOMATED SETUP")
print("=" * 60)
print("This script will set up your trading bot automatically")
print("=" * 60)
def check_python():
"""Check Python version"""
print("π Checking Python version...")
if sys.version_info < (3, 8):
print("β Python 3.8+ required. Please upgrade Python.")
return False
print(f"β
Python {sys.version.split()[0]} detected")
return True
def install_dependencies():
"""Install required dependencies"""
print("\nπ¦ Installing dependencies...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("β
Dependencies installed successfully")
return True
except subprocess.CalledProcessError:
print("β Failed to install dependencies")
return False
def create_directories():
"""Create necessary directories"""
print("\nπ Creating directories...")
directories = ["config", "logs", "results"]
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print(f"β
Created directory: {directory}")
def setup_credentials():
"""Setup API credentials"""
print("\nπ Setting up API credentials...")
config_dir = Path("config")
config_dir.mkdir(exist_ok=True)
credentials_file = config_dir / "credentials.json"
if credentials_file.exists():
print("β
Credentials file already exists")
return True
print("Please enter your Binance API credentials:")
api_key = input("API Key: ").strip()
api_secret = input("API Secret: ").strip()
if not api_key or not api_secret:
print("β API credentials cannot be empty")
return False
credentials = {
"binance": {
"api_key": api_key,
"api_secret": api_secret
}
}
with open(credentials_file, 'w') as f:
json.dump(credentials, f, indent=2)
print("β
Credentials saved successfully")
return True
def create_bot_config():
"""Create bot configuration file"""
print("\nβοΈ Creating bot configuration...")
config_file = Path("config/bot_config.json")
if config_file.exists():
print("β
Bot config already exists")
return
bot_config = {
"testnet": True,
"symbols": ["BTCUSDT", "ETHUSDT"],
"strategies": {
"liquidity": {"enabled": True, "weight": 1.0},
"momentum": {"enabled": True, "weight": 1.0},
"chart_patterns": {"enabled": True, "weight": 1.0},
"candlestick_patterns": {"enabled": True, "weight": 1.0}
},
"risk_config": {
"max_position_size": 0.02,
"daily_loss_limit": 0.05,
"max_drawdown": 0.15,
"stop_loss_pct": 0.02,
"take_profit_pct": 0.04
},
"notification_config": {
"enabled": True,
"channels": ["console"]
},
"logging_config": {
"level": "INFO",
"log_dir": "logs"
}
}
with open(config_file, 'w') as f:
json.dump(bot_config, f, indent=2)
print("β
Bot configuration created")
def test_setup():
"""Test the setup"""
print("\nπ§ͺ Testing setup...")
try:
# Test credentials loading
with open('config/credentials.json', 'r') as f:
creds = json.load(f)
if 'binance' in creds and 'api_key' in creds['binance']:
print("β
Credentials format is valid")
else:
print("β Invalid credentials format")
return False
# Test imports
try:
from binance.client import Client
print("β
Binance library imported successfully")
except ImportError:
print("β Failed to import Binance library")
return False
print("β
Setup test passed")
return True
except Exception as e:
print(f"β Setup test failed: {e}")
return False
def show_next_steps():
"""Show next steps to user"""
print("\nπ SETUP COMPLETE!")
print("=" * 60)
print("Your trading bot is ready to use!")
print("\nπ Next Steps:")
print("\n1. π Run Adaptive Scalping Scanner:")
print(" python scalping_scanner.py")
print("\n2. π― Run Strategy Scanner:")
print(" python strategy_scanner.py")
print("\n3. π€ Execute Trades:")
print(" python trading_executor.py")
print("\nπ Documentation:")
print(" - Read QUICK_START.md for detailed instructions")
print(" - Check README.md for full documentation")
print("\nπ‘οΈ Safety Note:")
print(" - Bot is configured for TESTNET by default")
print(" - Change 'testnet': false in config/bot_config.json for live trading")
print("\nπ Happy Trading!")
def main():
"""Main setup function"""
print_header()
# Check prerequisites
if not check_python():
return False
# Install dependencies
if not install_dependencies():
return False
# Create directories
create_directories()
# Setup credentials
if not setup_credentials():
return False
# Create bot config
create_bot_config()
# Test setup
if not test_setup():
return False
# Show next steps
show_next_steps()
return True
if __name__ == "__main__":
try:
success = main()
if not success:
print("\nβ Setup failed. Please check the errors above.")
sys.exit(1)
except KeyboardInterrupt:
print("\n\nπ Setup cancelled by user")
sys.exit(1)
except Exception as e:
print(f"\nβ Unexpected error: {e}")
sys.exit(1)