Skip to content

shuvivyas/Live-Trading-Simulation

Repository files navigation

📈 Live Trading Simulation – Algo Trading with Backtesting, Paper Trading & Live Data

📘 Overview

This project implements a full algorithmic trading simulation system with support for:

  • Historical backtesting
  • Real-time paper trading
  • Automated strategy execution
  • Portfolio state tracking
  • Interactive analytics dashboard
  • REST + WebSocket market data services

It uses FastAPI, Streamlit, PostgreSQL, and yFinance to recreate a realistic end-to-end trading workflow for research, experimentation, and educational purposes.


🎯 Objectives

🤖 Automated Trading

  • Implements two algorithmic trading strategies:
    • SMA Crossover
    • RSI Momentum
  • Generates deterministic buy/sell signals from historical or live data.

💹 Backtesting & Paper Trading

  • Simulates virtual trading with cash, positions, and PnL tracking.
  • Logs trades and equity snapshots.
  • Provides complete historical performance curves.

🛢 Backend Data & APIs

  • REST APIs for trades, equity, portfolio state, and strategy execution.
  • WebSockets for streaming live ticks and portfolio updates.
  • PostgreSQL storage for persistent analytics.

📊 Dashboard Visualization

  • Real-time equity & price charts
  • Trade markers
  • Portfolio metrics
  • Backtest trigger button
  • Live simulation controls

⚙️ Tech Stack

  • FastAPI
  • Streamlit
  • PostgreSQL
  • SQLAlchemy
  • yFinance
  • Plotly
  • TA indicators (ta)

🗂 Project Structure

/trading
├── /backend
│ ├── main.py
│ ├── api.py
│ ├── backtest.py
│ ├── database.py
│ ├── models.py
│ ├── strategies.py
│ ├── paper_trading.py

├── dashboard.py
├── connect.py
├── db.py
├── requirements.txt
└── /portfolio_state


🚀 Setup Instructions

1. Clone

git clone https://github.com/shuvivyas/Live-Trading-Simulation.git
cd Live-Trading-Simulation

2. Virtual Environment

python -m venv env
env\Scripts\activate (Windows)
source env/bin/activate (Linux/Mac)

3. Install Dependencies

pip install -r requirements.txt


🛢 Database Setup

  1. Create PostgreSQL DB: trading
  2. Update credentials if needed
  3. Initialize tables: python trading/db.py

🖥️ Run Backend (FastAPI)

uvicorn trading.backend.api:app --reload --port 8000

API Docs → http://127.0.0.1:8000/docs


📊 Run Dashboard

streamlit run trading/dashboard.py


📡 API Overview

GET /api/trades
GET /api/equity
GET /api/portfolio
GET /api/run_strategy

WS /ws/market/{symbol}
WS /ws/snapshots


📘 Example Output

{ "symbol": "AAPL", "strategy": "sma_crossover", "portfolio": { "cash": 0, "position": 44.42, "equity": 11347.88 } }

About

Lightweight trading simulator with backtesting, pseudo-live execution, and real-time dashboard.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages