# Secure Setup Guide for TradingAgents This guide will help you set up TradingAgents with security best practices in mind. ## Prerequisites - Python 3.10 or higher - Git - API keys for OpenAI and Alpha Vantage ## Step 1: Clone the Repository ```bash git clone https://github.com/TauricResearch/TradingAgents.git cd TradingAgents ``` ## Step 2: Create Virtual Environment **Always use a virtual environment** to isolate dependencies: ```bash # Create virtual environment python3 -m venv venv # Activate it # On macOS/Linux: source venv/bin/activate # On Windows: # venv\Scripts\activate ``` ## Step 3: Install Dependencies Securely ```bash # Upgrade pip first pip install --upgrade pip # Install dependencies from requirements.txt pip install -r requirements.txt # Optional: Install development dependencies pip install pytest bandit black flake8 mypy safety ``` ### Verify Dependency Security ```bash # Check for known vulnerabilities pip install safety safety check # Or use pip-audit pip install pip-audit pip-audit ``` ## Step 4: Configure Environment Variables **CRITICAL: Never hardcode API keys in your code!** ### Create .env File ```bash # Copy the example file cp .env.example .env # Edit .env with your actual values # Use your preferred editor (nano, vim, code, etc.) nano .env ``` ### Fill in Your API Keys Edit `.env` to include your actual API keys: ```bash # Required API Keys OPENAI_API_KEY=sk-your-actual-openai-key-here ALPHA_VANTAGE_API_KEY=your-actual-alpha-vantage-key-here # Optional: Custom directories TRADINGAGENTS_DATA_DIR=/secure/path/to/data TRADINGAGENTS_RESULTS_DIR=/secure/path/to/results # Optional: Logging LOG_LEVEL=INFO ``` ### Verify .env is Gitignored ```bash # Verify .env is in .gitignore cat .gitignore | grep ".env" # Should output: .env ``` ## Step 5: Secure Your API Keys ### Get API Keys 1. **OpenAI API Key**: - Go to https://platform.openai.com/api-keys - Create a new secret key - Copy it immediately (you won't see it again) 2. **Alpha Vantage API Key**: - Go to https://www.alphavantage.co/support/#api-key - Fill in the form to get a free API key - Copy the key from the email ### Protect Your Keys ```bash # Set proper permissions on .env file (Unix-like systems) chmod 600 .env # Verify permissions ls -l .env # Should show: -rw------- ``` ### API Key Best Practices 1. **Use separate keys** for development and production 2. **Rotate keys regularly** (every 90 days recommended) 3. **Set spending limits** in your API provider dashboard 4. **Monitor usage** regularly for unusual activity 5. **Never share keys** via email, Slack, or other insecure channels 6. **Revoke immediately** if you suspect compromise ## Step 6: Create Secure Data Directories ```bash # Create directories with proper permissions mkdir -p data results # Set restrictive permissions (Unix-like systems) chmod 700 data results # Verify ls -ld data results # Should show: drwx------ ``` ## Step 7: Verify Installation ```bash # Test import python -c "from tradingagents.graph.trading_graph import TradingAgentsGraph; print('Success!')" # Run security validators test python -c "from tradingagents.security import validate_ticker; print(validate_ticker('AAPL'))" ``` ## Step 8: Run Security Checks ### Static Security Analysis ```bash # Run Bandit security linter bandit -r tradingagents/ -ll # Check for common security issues python -m bandit -r tradingagents/ -f json -o security-report.json ``` ### Check for Secrets in Git History ```bash # Install trufflehog or gitleaks # Using gitleaks: docker run -v $(pwd):/path zricethezav/gitleaks:latest detect --source="/path" -v # Or manually search git log -p | grep -i "api[_-]key\|secret\|password" | head -20 ``` ## Step 9: Configure Logging Create a logging configuration file: ```bash # Create logs directory mkdir -p logs chmod 700 logs # Create logging config cat > logging_config.json < .pre-commit-config.yaml <