Skip to content

About

A Python-based algorithmic trading bot with backtesting and live paper trading via Alpaca.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

📈 Python Algorithmic Trading Bot Dashboard

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.


🖼️ Screenshots

Here's a look at the different sections of the Trading Bot Dashboard:

Full Dashboard Overview Backtest Strategy & Results
Full Dashboard Screenshot Backtest Strategy Card
Live Bot Control Live Paper Trading Status
Live Bot Control Card Live Paper Trading Status Card

✨ Features

  • 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 .env files to store sensitive API keys securely.

🛠️ Technology Stack

  • 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

🔑 API Key Setup

This project requires API keys from two services. You need to store them in a .env file in the root project directory.

  1. Alpha Vantage:
    • Go to Alpha Vantage and claim your free API key.
    • Add it to your .env file:
      ALPHA_VANTAGE_KEY="YOUR_ALPHA_VANTAGE_KEY"
      
  2. 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 .env file:
      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"

About

A Python-based algorithmic trading bot with backtesting and live paper trading via Alpaca.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages