chore: Second cleanup wave - organize root directory
- Archive: 85 agent .txt files → docs/archive/agents/legacy_txt/ - Scripts: Move 110 shell scripts → scripts/ (keep deploy.sh in root) - Models: Move 18 .safetensors → ml/models/checkpoints/training_artifacts/ - Delete: 34 directories (~33GB freed) - target/, coverage_*, test artifacts - Build: Clean 14 build artifacts (.rlib, .o, .pid, binaries) - Tests: Move 14 .rs files → tests/standalone/ - SQL: Move 5 files → sql/ (keep init-db*.sql for Docker) - Wave 153: Archive to docs/archive/historical/wave153/ - Docs: Archive 9 markdown files to wave_d/reports/ and historical/ Total impact: ~34GB freed (both waves), root directory cleaned from 583 to ~40 essential files Directory count reduced from 65 to 31 (52% reduction) All historical data preserved in organized archive structure
This commit is contained in:
144
scripts/start.sh
Executable file
144
scripts/start.sh
Executable file
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
# Foxhunt HFT Trading System - Complete System Startup
|
||||
# Starts 3 standalone services + databases as per TLI_PLAN.md architecture
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}🦊 Starting Foxhunt HFT Trading System${NC}"
|
||||
echo "===================================================="
|
||||
echo "Architecture: TLI Client → 3 Standalone Services → Docker Databases"
|
||||
echo ""
|
||||
|
||||
# Function to check if a port is available
|
||||
check_port() {
|
||||
local port=$1
|
||||
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to wait for service to be ready
|
||||
wait_for_service() {
|
||||
local service_name=$1
|
||||
local port=$2
|
||||
local max_attempts=30
|
||||
local attempt=0
|
||||
|
||||
echo -e "${YELLOW}⏳ Waiting for $service_name on port $port...${NC}"
|
||||
while [ $attempt -lt $max_attempts ]; do
|
||||
if nc -z localhost $port 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ $service_name is ready${NC}"
|
||||
return 0
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo -e "${RED}❌ $service_name failed to start on port $port${NC}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Step 1: Start Docker databases
|
||||
echo -e "${BLUE}🗄️ Starting Docker databases...${NC}"
|
||||
if ! command -v docker-compose >/dev/null 2>&1 && ! command -v docker >/dev/null 2>&1; then
|
||||
echo -e "${RED}❌ Docker/docker-compose not found. Please install Docker.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use docker compose (newer) or docker-compose (older)
|
||||
DOCKER_COMPOSE_CMD="docker compose"
|
||||
if ! command -v docker >/dev/null 2>&1 || ! docker compose version >/dev/null 2>&1; then
|
||||
DOCKER_COMPOSE_CMD="docker-compose"
|
||||
fi
|
||||
|
||||
echo "Starting databases with $DOCKER_COMPOSE_CMD..."
|
||||
$DOCKER_COMPOSE_CMD up -d
|
||||
|
||||
# Wait for databases to be ready
|
||||
echo -e "${YELLOW}⏳ Waiting for databases to initialize...${NC}"
|
||||
sleep 15
|
||||
|
||||
# Step 2: Set environment variables for database connections
|
||||
export DATABASE_URL="postgresql://trading_service:trading_dev_password@localhost:5432/foxhunt"
|
||||
export BACKTESTING_DATABASE_URL="postgresql://backtesting_service:backtesting_dev_password@localhost:5432/foxhunt_backtesting"
|
||||
export ML_DATABASE_URL="postgresql://ml_service:ml_dev_password@localhost:5432/foxhunt_ml_training"
|
||||
export REDIS_URL="redis://localhost:6379"
|
||||
export INFLUXDB_URL="http://localhost:8086"
|
||||
export RUST_LOG="info"
|
||||
|
||||
# Step 3: Check ports and stop conflicting services
|
||||
echo -e "${BLUE}🔍 Checking service ports...${NC}"
|
||||
TRADING_PORT=50051
|
||||
BACKTESTING_PORT=50052
|
||||
ML_TRAINING_PORT=50053
|
||||
|
||||
# Kill any existing services
|
||||
pkill -f "trading_service" || true
|
||||
pkill -f "backtesting_service" || true
|
||||
pkill -f "ml_training_service" || true
|
||||
sleep 2
|
||||
|
||||
# Step 4: Build and start the 3 standalone services
|
||||
echo -e "${BLUE}🏗️ Building services...${NC}"
|
||||
if ! cargo build --release --bin trading_service --bin backtesting_service -p ml_training_service; then
|
||||
echo -e "${RED}❌ Failed to build services. Check compilation errors.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Services built successfully${NC}"
|
||||
|
||||
# Step 5: Start services in background
|
||||
echo -e "${BLUE}🚀 Starting standalone services...${NC}"
|
||||
|
||||
# Start Trading Service (port 50051)
|
||||
echo "📈 Starting Trading Service..."
|
||||
cargo run --release --bin trading_service &
|
||||
TRADING_PID=$!
|
||||
echo $TRADING_PID > .trading_service.pid
|
||||
|
||||
# Start Backtesting Service (port 50052)
|
||||
echo "🔄 Starting Backtesting Service..."
|
||||
cargo run --release -p backtesting_service &
|
||||
BACKTESTING_PID=$!
|
||||
echo $BACKTESTING_PID > .backtesting_service.pid
|
||||
|
||||
# Start ML Training Service (port 50053)
|
||||
echo "🧠 Starting ML Training Service..."
|
||||
cargo run --release -p ml_training_service &
|
||||
ML_TRAINING_PID=$!
|
||||
echo $ML_TRAINING_PID > .ml_training_service.pid
|
||||
|
||||
# Step 6: Wait for all services to be ready
|
||||
echo -e "${YELLOW}⏳ Waiting for services to start...${NC}"
|
||||
wait_for_service "Trading Service" $TRADING_PORT
|
||||
wait_for_service "Backtesting Service" $BACKTESTING_PORT
|
||||
wait_for_service "ML Training Service" $ML_TRAINING_PORT
|
||||
|
||||
# Step 7: Display system status
|
||||
echo -e "${GREEN}🎉 Foxhunt HFT System is running!${NC}"
|
||||
echo ""
|
||||
echo "System Architecture:"
|
||||
echo "├── Trading Service: localhost:$TRADING_PORT (PID: $TRADING_PID)"
|
||||
echo "├── Backtesting Service: localhost:$BACKTESTING_PORT (PID: $BACKTESTING_PID)"
|
||||
echo "├── ML Training Service: localhost:$ML_TRAINING_PORT (PID: $ML_TRAINING_PID)"
|
||||
echo "└── Databases: PostgreSQL(5432), InfluxDB(8086), Redis(6379)"
|
||||
echo ""
|
||||
echo "To start TLI client: cargo run --release -p tli"
|
||||
echo "To stop system: ./stop.sh"
|
||||
echo "To view logs: docker logs foxhunt-postgres"
|
||||
echo ""
|
||||
echo -e "${GREEN}System ready for TLI connection!${NC}"
|
||||
|
||||
# Keep services running and handle shutdown
|
||||
trap 'echo -e "\n${YELLOW}🛑 Shutting down services...${NC}"; ./stop.sh; exit 0' INT
|
||||
echo "Press Ctrl+C to stop all services and databases"
|
||||
wait
|
||||
Reference in New Issue
Block a user