Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 2.3 KB

File metadata and controls

64 lines (46 loc) · 2.3 KB

Live Trading with Alpaca

This guide explains how to set up the AI Hedge Fund for live or paper trading using the Alpaca brokerage.

1. Setup Alpaca Account

  1. Go to Alpaca and create an account.
  2. Log in to your dashboard and navigate to the Paper Trading section (recommended for first-time use).
  3. Generate your API Key ID and Secret Key.

2. Configure Environment

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.markets

Note: For live trading, change the ALPACA_BASE_URL to https://api.alpaca.markets.

3. Running the Live Trader

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

Command Line Arguments:

  • --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.

4. Automation (VPS Deployment)

To make income 24/7, it is recommended to run this on a VPS (like DigitalOcean or AWS) using a cron job.

Step 1: Install Dependencies on VPS

git clone <your-repo-url>
cd ai-hedge-fund
poetry install

Step 2: Set up a Cron Job

Open your crontab editor:

crontab -e

Add 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

5. Important Disclaimers

  • 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 Manager agent in this system provides suggestions, but you are ultimately responsible for your capital.
  • Monitoring: Check your trading.log regularly for any errors or failed orders.