-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapple_container_elvis.sh
More file actions
executable file
·329 lines (274 loc) · 8.37 KB
/
apple_container_elvis.sh
File metadata and controls
executable file
·329 lines (274 loc) · 8.37 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/bash
# ELVIS Trading Bot - Apple Container System Integration
# One-click setup and management for Apple Container app
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'
print_header() {
echo -e "${BLUE}$1${NC}"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}$1${NC}"
}
show_banner() {
echo -e "${PURPLE}"
cat << "EOF"
███████╗██╗ ██╗ ██╗██╗███████╗
██╔════╝██║ ██║ ██║██║██╔════╝
█████╗ ██║ ██║ ██║██║███████╗
██╔══╝ ██║ ╚██╗ ██╔╝██║╚════██║
███████╗███████╗ ╚████╔╝ ██║███████║
╚══════╝╚══════╝ ╚═══╝ ╚═╝╚══════╝
Enhanced Leveraged Virtual Investment System
Apple Container Integration
EOF
echo -e "${NC}"
}
show_help() {
echo "ELVIS Trading Bot - Apple Container Management"
echo ""
echo "Usage: $0 [COMMAND]"
echo ""
echo "Commands:"
echo " setup - Complete setup for Apple Container system"
echo " start - Start ELVIS trading bot"
echo " stop - Stop all services"
echo " restart - Restart all services"
echo " status - Show service status"
echo " logs - Show ELVIS logs"
echo " reset - Reset paper trading to initial state"
echo " dashboard - Open trading dashboard"
echo " test - Run container setup tests"
echo " update - Update containers"
echo " backup - Backup trading data"
echo " help - Show this help"
echo ""
echo "Examples:"
echo " $0 setup # First-time setup"
echo " $0 start # Start trading"
echo " $0 logs # Monitor activity"
}
check_requirements() {
if ! command -v docker &> /dev/null; then
print_error "❌ Docker is not installed"
echo "Please install Docker Desktop for Mac:"
echo "https://www.docker.com/products/docker-desktop/"
exit 1
fi
if ! docker info &> /dev/null; then
print_error "❌ Docker is not running"
echo "Please start Docker Desktop"
exit 1
fi
}
cmd_setup() {
print_header "🍎 Setting up ELVIS for Apple Container System"
check_requirements
if [[ -f "./setup_apple_containers.sh" ]]; then
./setup_apple_containers.sh
else
print_error "Setup script not found!"
exit 1
fi
print_success "✅ Setup complete!"
echo ""
echo "Next steps:"
echo " $0 start # Start trading"
echo " $0 dashboard # Open dashboard"
}
cmd_start() {
print_header "🚀 Starting ELVIS Trading Bot"
check_requirements
# Use Apple-optimized configuration if available
if [[ -f "docker-compose.apple.yml" ]]; then
export COMPOSE_FILE="docker-compose.yml:docker-compose.apple.yml"
print_success "Using Apple Container optimizations"
fi
docker-compose up -d
# Wait for services to be ready
print_success "Waiting for services to start..."
sleep 10
# Check if services are healthy
if docker-compose ps | grep -q "Up"; then
print_success "✅ ELVIS Trading Bot started successfully!"
echo ""
echo "📊 Access points:"
echo " • Trading Dashboard: http://localhost:5050"
echo " • Grafana Metrics: http://localhost:3000 (admin/admin)"
echo " • Prometheus: http://localhost:9090"
echo ""
echo "💰 Paper Trading:"
echo " • Starting with \$1000 USDT + \$1000 BNB"
echo " • Bonenkamp HFT strategy active"
echo " • 5-minute trading intervals"
echo ""
echo "📱 Management:"
echo " $0 logs # View trading activity"
echo " $0 status # Check system status"
echo " $0 stop # Stop trading"
else
print_error "❌ Some services failed to start"
echo "Check logs: $0 logs"
exit 1
fi
}
cmd_stop() {
print_header "🛑 Stopping ELVIS Trading Bot"
docker-compose down
print_success "✅ ELVIS stopped"
}
cmd_restart() {
print_header "🔄 Restarting ELVIS Trading Bot"
cmd_stop
sleep 2
cmd_start
}
cmd_status() {
print_header "📊 ELVIS Service Status"
echo "Container Status:"
docker-compose ps
echo ""
echo "Resource Usage:"
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}" 2>/dev/null || echo "Docker stats unavailable"
echo ""
echo "Health Checks:"
for service in elvis-bot postgres redis; do
if docker-compose ps "$service" | grep -q "Up"; then
print_success "✅ $service: Running"
else
print_error "❌ $service: Stopped"
fi
done
}
cmd_logs() {
print_header "📋 ELVIS Trading Logs"
if [[ $# -gt 1 ]]; then
# Follow logs with tail
docker-compose logs -f --tail=100 elvis-bot
else
# Show recent logs
docker-compose logs --tail=50 elvis-bot
fi
}
cmd_reset() {
print_header "🔄 Resetting Paper Trading"
print_warning "This will reset all trading data to initial state:"
print_warning "• Clear all trades"
print_warning "• Clear all positions"
print_warning "• Reset to \$1000 USDT + \$1000 BNB"
echo ""
read -p "Continue? (y/N): " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
docker-compose exec elvis-bot python reset_paper_trading.py
print_success "✅ Paper trading reset complete"
else
echo "Reset cancelled"
fi
}
cmd_dashboard() {
print_header "📊 Opening Trading Dashboard"
if command -v open &> /dev/null; then
open http://localhost:5050
print_success "Dashboard opened in browser"
else
echo "Open manually: http://localhost:5050"
fi
}
cmd_test() {
print_header "🧪 Running Container Tests"
if [[ -f "./test_container_setup.sh" ]]; then
./test_container_setup.sh
else
print_error "Test script not found!"
exit 1
fi
}
cmd_update() {
print_header "⬆️ Updating ELVIS Containers"
print_success "Pulling latest images..."
docker-compose pull
print_success "Rebuilding ELVIS..."
docker-compose build elvis-bot
print_success "Restarting services..."
docker-compose up -d
print_success "✅ Update complete"
}
cmd_backup() {
print_header "💾 Backing up ELVIS Data"
backup_dir="backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup_dir"
print_success "Backing up database..."
docker-compose exec -T postgres pg_dump -U elvis_user elvis_trading > "$backup_dir/database.sql"
print_success "Backing up models..."
tar -czf "$backup_dir/models.tar.gz" models/ 2>/dev/null || true
print_success "Backing up logs..."
tar -czf "$backup_dir/logs.tar.gz" logs/ 2>/dev/null || true
print_success "✅ Backup created: $backup_dir"
}
# Main command dispatcher
main() {
show_banner
if [[ $# -eq 0 ]]; then
show_help
exit 0
fi
case "$1" in
"setup")
cmd_setup "$@"
;;
"start")
cmd_start "$@"
;;
"stop")
cmd_stop "$@"
;;
"restart")
cmd_restart "$@"
;;
"status")
cmd_status "$@"
;;
"logs")
cmd_logs "$@"
;;
"reset")
cmd_reset "$@"
;;
"dashboard")
cmd_dashboard "$@"
;;
"test")
cmd_test "$@"
;;
"update")
cmd_update "$@"
;;
"backup")
cmd_backup "$@"
;;
"help"|"-h"|"--help")
show_help
;;
*)
print_error "Unknown command: $1"
echo ""
show_help
exit 1
;;
esac
}
# Run main function
main "$@"