This project is a full-stack algorithmic trading application built entirely in Python. It features a backtesting engine to test trading strategies against historical data and integrates with Alpaca's API for live paper trading (simulated trading with real market data but fake money). The entire system is controlled via a modern, interactive web dashboard built with Flask and Bootstrap.
Here's a look at the different sections of the Trading Bot Dashboard:
| Full Dashboard Overview | Backtest Strategy & Results |
|---|---|
![]() |
![]() |
| Live Bot Control | Live Paper Trading Status |
|---|---|
![]() |
![]() |
- Backtesting Engine: Tests a Moving Average Crossover strategy on historical stock data fetched from Alpha Vantage.
- Live Paper Trading: Connects to Alpaca's paper trading API to execute the strategy in real-time using simulated money.
- Web Dashboard: A comprehensive UI built with Flask, Bootstrap, and Plotly.js to:
- Run backtests for any stock ticker.
- Visualize backtest results with interactive candlestick charts, moving averages, buy/sell signals, and portfolio value growth.
- Start and stop the live trading bot for a specified ticker.
- Monitor live paper trading account status (cash, portfolio value), open positions, and recent orders.
- View real-time market open/closed status.
- Switch between light and dark themes.
- Modular Code: Separated logic for data fetching/backtesting (
backtester.py), Alpaca API interaction (alpaca_trader.py), live bot execution (live_bot.py), and the web server (api.py). - Secure API Key Management: Uses
.envfiles to store sensitive API keys securely.
- Backend: Python, Flask, Pandas, NumPy, Alpha Vantage API, Alpaca Trade API
- Frontend: HTML, CSS, JavaScript (Vanilla), Bootstrap 5, Plotly.js
- Dependencies:
python-dotenv,alpaca-trade-api,alpha-vantage
This project requires API keys from two services. You need to store them in a .env file in the root project directory.
- Alpha Vantage:
- Go to Alpha Vantage and claim your free API key.
- Add it to your
.envfile:ALPHA_VANTAGE_KEY="YOUR_ALPHA_VANTAGE_KEY"
- Alpaca Markets:
- Sign up for a free Paper Trading account at Alpaca Markets.
- Navigate to your dashboard to generate an API Key ID and a Secret Key.
- Add them to your
.envfile:APCA_API_KEY_ID="YOUR_ALPACA_API_KEY_ID" APCA_API_SECRET_KEY="YOUR_ALPACA_SECRET_KEY"
.env Example:
ALPHA_VANTAGE_KEY="YOUR_ALPHA_VANTAGE_KEY"
APCA_API_KEY_ID="YOUR_ALPACA_API_KEY_ID"
APCA_API_SECRET_KEY="YOUR_ALPACA_SECRET_KEY"


