# Agent Bot - Download & Setup Instructions ## 📥 How to Get the Agent Bot ### Option 1: Direct Copy from Server If you have access to the server: ```bash # Navigate to the agent bot directory cd /root/lib/prod3/event_trader/trading_bot # Copy all files to your local directory cp -r /root/lib/prod3/event_trader/trading_bot ~/my_trading_bot # Or create a compressed archive cd /root/lib/prod3/event_trader tar -czf trading_bot.tar.gz trading_bot/ ``` ### Option 2: Download via Web Interface Visit the Event Trader API documentation: ``` http://localhost:8000/docs ``` Look for the "Agent Bot" section with download links. ### Option 3: Manual File Copy Copy these files and directories: ``` trading_bot/ ├── config.yaml # Configuration ├── demo_bot.py # Simple demo ├── strategy_bot.py # Multi-strategy bot ├── risk_managed_bot.py # Production bot (recommended) ├── backtest_example.py # Simple backtest ├── backtest_risk_managed.py # Advanced backtest ├── README.md # Quick start ├── DOWNLOAD-INSTRUCTIONS.md # This file │ ├── core/ │ ├── __init__.py │ ├── api_client.py # API integration │ ├── risk_manager.py # Risk management │ ├── trade_executor.py # Order execution │ └── portfolio_manager.py # Portfolio tracking │ ├── strategies/ │ ├── __init__.py │ ├── base_strategy.py # Base class │ ├── mean_reversion.py # Mean reversion │ └── momentum.py # Momentum strategy │ └── utils/ ├── __init__.py ├── indicators.py # Technical indicators └── backtester.py # Backtesting framework ``` --- ## ⚡ Quick Setup (After Download) ### 1. Install Dependencies ```bash pip install pyyaml aiohttp numpy ``` ### 2. Get API Key 1. Go to Event Trader dashboard 2. Navigate to API Settings 3. Create new key with `read` + `write` permissions 4. Copy key (starts with `evt_`) ### 3. Configure Bot Edit `config.yaml`: ```yaml api: api_key: "evt_YOUR_API_KEY_HERE" # ← Paste your key here base_url: "http://localhost:8000" bot: mode: "paper" # Start with paper trading initial_capital: 10000.0 ``` ### 4. Run Bot ```bash # Recommended: Full production bot python3 risk_managed_bot.py # Or simple demo python3 demo_bot.py # Or run backtests python3 backtest_risk_managed.py ``` --- ## 📁 What Each File Does ### Main Bots (Pick One to Run) **`demo_bot.py`** - Simple Demo - Basic market monitoring - Shows how to fetch data - Good for learning - ~125 lines **`strategy_bot.py`** - Multi-Strategy Bot - Runs multiple strategies - Paper trading mode - No risk management - ~250 lines **`risk_managed_bot.py`** - Production Bot ⭐ **RECOMMENDED** - Full risk management - Portfolio tracking - Stop-loss/take-profit - Ready for live trading - ~350 lines ### Backtest Scripts **`backtest_example.py`** - Simple Backtest - Compare 2 strategies - Single market condition - Basic performance metrics **`backtest_risk_managed.py`** - Advanced Backtest - Tests 4 market types (bull/bear/mixed/range) - Full risk management - Comprehensive metrics ### Core Modules (Don't Edit Unless You Know What You're Doing) **`core/api_client.py`** - Connects to Event Trader API - Rate limiting (100 req/min) - Error handling **`core/risk_manager.py`** - Kelly Criterion position sizing - Stop-loss/take-profit - Portfolio constraints - Risk metrics (VaR, Sharpe, etc.) **`core/trade_executor.py`** - Market & limit orders - Order book analysis - Slippage tracking - Circuit breaker **`core/portfolio_manager.py`** - Position tracking - P&L calculation - Performance metrics - Rebalancing ### Strategy Modules **`strategies/base_strategy.py`** - Base class for all strategies - Don't modify **`strategies/mean_reversion.py`** - Trades oversold/overbought conditions - Uses RSI + Bollinger Bands **`strategies/momentum.py`** - Follows trends - Uses MACD + EMA + ROC ### Utilities **`utils/indicators.py`** - 15+ technical indicators - RSI, MACD, Bollinger Bands, etc. **`utils/backtester.py`** - Backtest framework - Performance calculation --- ## 🎯 First Time Setup Checklist - [ ] Download all files - [ ] Install dependencies: `pip install pyyaml aiohttp numpy` - [ ] Get API key from Event Trader - [ ] Edit `config.yaml` with your API key - [ ] Set mode to "paper" in config - [ ] Run `python3 demo_bot.py` to test - [ ] Read `TRADING-BOT-QUICKSTART.md` - [ ] Run backtests to see performance - [ ] Start `risk_managed_bot.py` in paper mode - [ ] Monitor for 1+ week before going live --- ## 📖 Documentation Files After downloading, read these in order: 1. **`README.md`** - Quick overview 2. **`TRADING-BOT-QUICKSTART.md`** - Complete quick start 3. **`TRADING-BOT-USER-GUIDE.md`** - Detailed usage 4. **`TRADING-BOT-FINAL-SUMMARY.md`** - System overview --- ## 🔧 Customization ### Change Strategies Edit `config.yaml`: ```yaml strategies: mean_reversion: enabled: true # Turn on/off min_confidence: 0.6 momentum: enabled: false # Disable if you want min_confidence: 0.7 ``` ### Adjust Risk Settings ```yaml risk: max_position_size: 0.10 # Reduce to 10% max_drawdown: 0.10 # Stop at 10% loss stop_loss_pct: 0.03 # Tighter stop (3%) take_profit_pct: 0.15 # Bigger profit target (15%) ``` ### Change Update Frequency ```yaml bot: update_interval: 30 # Check every 30 seconds instead of 60 ``` --- ## ⚠️ Before Going Live **IMPORTANT CHECKLIST:** - [ ] Run in paper mode for **minimum 1 week** - [ ] Review all trades in logs - [ ] Understand why signals were generated - [ ] Verify stop-losses are working - [ ] Check performance metrics make sense - [ ] Start with **small capital** ($100-500) - [ ] Monitor **daily** for first week - [ ] Never trade more than you can afford to lose --- ## 🆘 Getting Help ### Check Logs ```bash # Run with log output to file python3 risk_managed_bot.py 2>&1 | tee bot.log # View logs tail -f bot.log ``` ### Common Issues **ModuleNotFoundError** ```bash pip install pyyaml aiohttp numpy ``` **API Connection Error** ```bash # Make sure API server is running curl http://localhost:8000/api/v2/markets?limit=1 ``` **No Signals Generated** - Check markets exist with status="active" - Verify strategies are enabled - Lower min_confidence in config --- ## 📊 File Sizes - Total: ~6,000 lines of code - Core modules: ~2,575 lines - Strategies: ~580 lines - Utilities: ~780 lines - Bots: ~1,200 lines --- ## 🎓 Learning Path 1. **Week 1**: Run `demo_bot.py`, understand basics 2. **Week 2**: Run backtests, study strategies 3. **Week 3**: Paper trade with `risk_managed_bot.py` 4. **Week 4**: Monitor performance, adjust settings 5. **Week 5+**: Consider live trading with small capital --- ## ✅ Verification After setup, verify it works: ```bash # Test imports python3 -c "from core.api_client import APIClient; print('✅ API Client OK')" python3 -c "from strategies.mean_reversion import MeanReversionStrategy; print('✅ Strategies OK')" python3 -c "from utils.indicators import calculate_rsi; print('✅ Indicators OK')" # Run demo (should not error) timeout 5 python3 demo_bot.py # If no errors, you're ready! ``` --- ## 🚀 You're Ready! The agent bot is now installed and ready to use. **Next:** Read `TRADING-BOT-QUICKSTART.md` for detailed usage instructions. **Happy Trading! 🎉** --- **Need Help?** Check the documentation files or review the code comments for detailed explanations.