Files
CryptoTrading/setup.sh
bnair123 6f602c0d19 Add core infrastructure: config, Binance adapter, docs, and auto-setup
- Add Pydantic settings with trading mode validation (paper/testnet/live)
- Implement Binance USDⓈ-M Futures adapter with hedge mode, isolated margin
- Add type definitions for orders, positions, and market data
- Create documentation (PLAN.md, ARCHITECTURE.md, SECURITY.md)
- Add setup.sh with uv/pip auto-detection for consistent dev environments
- Configure Docker multi-stage build and docker-compose services
- Add pyproject.toml with all dependencies and tool configs
2025-12-27 13:28:08 +04:00

151 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# TradeFinder Development Setup Script
# Works with both uv (preferred) and traditional venv+pip
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
# Check Python version
check_python() {
if command -v python3.11 &> /dev/null; then
PYTHON_CMD="python3.11"
elif command -v python3.12 &> /dev/null; then
PYTHON_CMD="python3.12"
elif command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
else
error "Python 3.11+ not found. Please install Python 3.11 or later."
fi
# Verify version
PY_VERSION=$($PYTHON_CMD -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
PY_MAJOR=$($PYTHON_CMD -c 'import sys; print(sys.version_info.major)')
PY_MINOR=$($PYTHON_CMD -c 'import sys; print(sys.version_info.minor)')
if [[ $PY_MAJOR -lt 3 ]] || [[ $PY_MAJOR -eq 3 && $PY_MINOR -lt 11 ]]; then
error "Python 3.11+ required, found $PY_VERSION"
fi
info "Using Python $PY_VERSION ($PYTHON_CMD)"
}
# Setup with uv (preferred - much faster)
setup_with_uv() {
info "Setting up with uv (fast mode)..."
# Create venv and install dependencies in one go
uv venv .venv --python "$PYTHON_CMD"
# Install the package with dev dependencies
uv pip install -e ".[dev]" --python .venv/bin/python
info "uv setup complete!"
}
# Setup with traditional venv + pip
setup_with_pip() {
info "Setting up with venv + pip..."
# Create virtual environment
$PYTHON_CMD -m venv .venv
# Activate and upgrade pip
source .venv/bin/activate
pip install --upgrade pip wheel setuptools
# Install the package with dev dependencies
pip install -e ".[dev]"
info "pip setup complete!"
}
# Install uv if not present (optional, user choice)
install_uv() {
info "Installing uv package manager..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add to current shell
export PATH="$HOME/.cargo/bin:$PATH"
if command -v uv &> /dev/null; then
info "uv installed successfully!"
return 0
else
warn "uv installation may require shell restart"
return 1
fi
}
# Main setup logic
main() {
echo ""
echo "╔═══════════════════════════════════════════╗"
echo "║ TradeFinder Development Setup ║"
echo "╚═══════════════════════════════════════════╝"
echo ""
check_python
# Check if uv is available
if command -v uv &> /dev/null; then
UV_VERSION=$(uv --version 2>/dev/null || echo "unknown")
info "Found uv: $UV_VERSION"
setup_with_uv
else
warn "uv not found. It's 10-100x faster than pip."
echo ""
read -p "Install uv? (recommended) [Y/n]: " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
if install_uv; then
setup_with_uv
else
warn "Falling back to pip..."
setup_with_pip
fi
else
info "Using traditional pip..."
setup_with_pip
fi
fi
# Create .env from example if it doesn't exist
if [[ ! -f .env ]] && [[ -f .env.example ]]; then
cp .env.example .env
info "Created .env from .env.example"
warn "Edit .env and add your Binance testnet API keys!"
fi
echo ""
echo "═══════════════════════════════════════════════"
echo ""
info "Setup complete! Next steps:"
echo ""
echo " 1. Activate the virtual environment:"
echo " source .venv/bin/activate"
echo ""
echo " 2. Edit .env with your Binance testnet keys:"
echo " Get keys from: https://testnet.binancefuture.com"
echo ""
echo " 3. Run tests:"
echo " pytest"
echo ""
echo " 4. Start developing!"
echo ""
}
main "$@"