Back to Projects
Alpaca Bot

Alpaca Bot

End-to-end financial data pipeline and trading automation project using historical stock data, GRU-based price prediction, feature engineering, and Alpaca API integration. The system selects tickers, generates predictions, and automates order placement using scheduled scripts.

Jun 2025 - Aug 2025 2 months

Tech Stack

PythonFinancial DataTime SeriesKerasBroker APIAWS

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