Back to Projects
Alpaca Bot

Alpaca Bot

This project automates a daily stock trading strategy using GRU-predicted highs and Alpaca API. It fetches historical stock data, predicts the next day's high, and places buy/sell orders on the market open and target price.

Jun 2025 - Aug 2025 2 months

Tech Stack

Broker APIPythonKerasAWSKeras

How It Works

  1. Before Market Open (closed_market.py):

    • Closes all current positions.
    • Predicts next-day high return for a list of tickers.
    • Selects the most promising ticker (highest predicted return over threshold).
    • Buys that stock using available cash at market open (OPG order).
  2. After Market Open (open_market.py):

    • Places a limit sell order at the predicted high.

Project Structure

FilePurpose
closed_market.pyExecutes before market opens (buy logic)
open_market.pyExecutes after market opens (sell logic)
trade.pyCloses all current positions
utils.pyPrediction logic + Alpaca helpers
alpacaWrappers.pyOrder, data, and account wrappers for Alpaca
tickers.jsonList of tickers and threshold values
models/Contains saved models and scalers

Environment Variables

Create a .env file in your root directory:

ALPACA_API_KEY=your_api_key
ALPACA_SECRET_KEY=your_secret_key

You can use Alpaca’s paper trading credentials for testing.

Setup

pip install -r requirements.txt

Packages:

alpaca-trade-api
pandas
pandas_market_calendars
python-dotenv
tensorflow
joblib

Model Predictions

Each stock in tickers.json must have:

{
  "SPY": {
    "threshold": 0.85
  },
  "QQQ": {
    "threshold": 0.90
  }
}

Trading Logic

Notes

View All Projects