This guide explains how to set up the AI Hedge Fund for live or paper trading using the Alpaca brokerage.
- Go to Alpaca and create an account.
- Log in to your dashboard and navigate to the Paper Trading section (recommended for first-time use).
- Generate your API Key ID and Secret Key.
Add your Alpaca credentials to your .env file (copy from .env.example if you haven't):
ALPACA_API_KEY=your_api_key_id
ALPACA_SECRET_KEY=your_secret_key
ALPACA_BASE_URL=https://paper-api.alpaca.marketsNote: For live trading, change the ALPACA_BASE_URL to https://api.alpaca.markets.
You can run the live trader from the command line. It will fetch your current portfolio from Alpaca, run the AI analysis, and submit orders automatically.
poetry run python src/live_trader.py --tickers AAPL,MSFT,NVDA--tickers: Comma-separated list of stocks to trade (Required).--model-name: The LLM model to use (default:gpt-4o).--model-provider: The provider for the model (default:OpenAI).--show-reasoning: Include this flag to see the agents' logic in the console.
To make income 24/7, it is recommended to run this on a VPS (like DigitalOcean or AWS) using a cron job.
git clone <your-repo-url>
cd ai-hedge-fund
poetry installOpen your crontab editor:
crontab -eAdd a line to run the bot every weekday at 10:00 AM EST (when the market has settled):
# Example: Running at 10:00 AM EST (15:00 UTC)
0 15 * * 1-5 cd /path/to/ai-hedge-fund && /home/user/.local/bin/poetry run python src/live_trader.py --tickers AAPL,MSFT,NVDA >> /path/to/ai-hedge-fund/trading.log 2>&1- Paper Trading First: Always run in paper trading mode for at least 2-4 weeks to verify the strategy is profitable in current market conditions.
- Risk Management: The
Risk Manageragent in this system provides suggestions, but you are ultimately responsible for your capital. - Monitoring: Check your
trading.logregularly for any errors or failed orders.