Follow these steps to set up and start your Alpaca paper trading bot using FastAPI and Docker Compose.
git clone https://github.com/pilotwaffle/trading-bot.git
cd trading-bot- Copy and paste the following example, or edit your existing
.envfile with your Alpaca Paper Trading API keys:
# .env
ALPACA_API_KEY=YOUR_ALPACA_PAPER_API_KEY
ALPACA_API_SECRET=YOUR_ALPACA_PAPER_API_SECRET
# Compatibility (recommended)
ALPACA_PAPER_API_KEY=YOUR_ALPACA_PAPER_API_KEY
ALPACA_PAPER_SECRET_KEY=YOUR_ALPACA_PAPER_API_SECRET
ALPACA_SECRET_KEY=YOUR_ALPACA_PAPER_API_SECRET
# Dashboard Authentication
APP_USER_ID=admin
APP_PASSWORD=admin123
# Optional settings
DEBUG=true
LOG_LEVEL=INFO- You can adjust
APP_USER_ID,APP_PASSWORD, or logging settings in.envas needed.
- Get Docker Desktop for Windows/Mac, or use your package manager for Linux.
- Verify installation:
docker --version
docker compose versiondocker compose up --build- This will:
- Build the Docker image using your repo's
Dockerfile - Load environment variables from
.env - Expose FastAPI at http://localhost:8000
- Build the Docker image using your repo's
- Open your browser at: http://localhost:8000
- The FastAPI docs are available at: http://localhost:8000/docs
- Login with credentials set in
.env(APP_USER_ID/APP_PASSWORD).
- Logs are written to
logs/(mounted from the container). - Trading data is stored in
data/if your bot writes to this folder.
- In your terminal, press
Ctrl+Cto stop. - Or, to fully stop and clean up containers:
docker compose down- Pull the latest code and rebuild:
git pull
docker compose up --build- Check logs in the
logs/directory for errors. - Make sure your
.envhas your correct Alpaca paper trading keys. - For Docker issues, try restarting Docker Desktop or running with
sudoon Linux.
Q: Do I need to install Python packages manually?
A: No, Docker handles all requirements for you.
Q: Can I run without Docker?
A: Yes! Just create a virtual environment, install requirements.txt, and run python main.py.
But Docker is recommended for reproducibility.
Q: Can I trade live?
A: Not by default—this setup is for Alpaca paper trading only. For live trading, you must update your .env and possibly code.
That’s it! Your trading bot is ready to go.
Happy (paper) trading! 🎉