Skip to content

tuxninja/trading-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Trading Sentiment Analysis SaaS Platform

A comprehensive SaaS paper trading platform that uses sentiment analysis to generate trading recommendations and track portfolio performance. Built for traders, investors, and financial professionals who want to test strategies risk-free.

Trading Platform FastAPI React License

๐Ÿ“‹ Table of Contents

๐Ÿ“š Documentation

Setup Guides

Operations

Technical Reference

๐ŸŽฏ Overview

The Trading Sentiment Analysis Platform is a full-stack application that combines real-time market data, news sentiment analysis, and automated trading strategies to help users make informed investment decisions through paper trading.

Key Technologies

  • Backend: FastAPI (Python), SQLAlchemy, PostgreSQL/SQLite
  • Frontend: React, Tailwind CSS, Recharts
  • Data Sources: Yahoo Finance API, News APIs, Alternative free sources
  • Sentiment Analysis: VADER, TextBlob
  • Scheduling: Python schedule library

โœจ Features

Trading & Portfolio Management

  • ๐Ÿ“Š Paper Trading: Risk-free trading simulation with real market data
  • ๐Ÿ’ผ Portfolio Tracking: Real-time portfolio value and performance metrics
  • ๐Ÿ“ˆ Historical Performance: Interactive charts showing portfolio evolution
  • ๐ŸŽฏ Position Management: Track open/closed positions with detailed P&L

Sentiment Analysis

  • ๐Ÿ“ฐ News Sentiment: Automated analysis of financial news and articles
  • ๐Ÿ” Multi-Source Data: Yahoo Finance, MarketWatch, Reuters, CNBC
  • ๐Ÿง  Smart Recommendations: AI-powered trade suggestions based on sentiment
  • ๐Ÿ“Š Sentiment Scoring: Comprehensive sentiment metrics per stock

Market Intelligence

  • ๐Ÿ” Market Scanner: Discover trending stocks from news analysis
  • ๐Ÿ“‹ Stock Watchlists: Track multiple securities with real-time updates
  • ๐Ÿ“ˆ Technical Indicators: Market cap, P/E ratios, dividend yields
  • ๐Ÿšจ Alert System: Notifications for significant sentiment changes

Automation & Scheduling

  • โฐ Automated Data Collection: Scheduled market data updates
  • ๐Ÿค– Strategy Execution: Automated trading based on sentiment signals
  • ๐Ÿ“… Flexible Scheduling: Configurable collection intervals
  • ๐Ÿ”„ Background Processing: Non-blocking data updates

Analytics & Reporting

  • ๐Ÿ“Š Performance Metrics: Win rate, Sharpe ratio, max drawdown
  • ๐Ÿ“ˆ Interactive Charts: Real-time portfolio performance visualization
  • ๐Ÿ“‹ Trade History: Detailed records of all trading activity
  • ๐Ÿ’ฐ P&L Analysis: Comprehensive profit/loss tracking

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   React Frontend โ”‚โ”€โ”€โ”€โ”€โ”‚   FastAPI Backend โ”‚โ”€โ”€โ”€โ”€โ”‚   Database      โ”‚
โ”‚   (Port 3000)    โ”‚    โ”‚   (Port 8000)     โ”‚    โ”‚   (SQLite/PG)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚                   โ”‚
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚  Data Scheduler โ”‚ โ”‚  External APIs โ”‚
            โ”‚  (Background)   โ”‚ โ”‚  (Yahoo, News) โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Backend Services

  • Trading Service: Handles paper trades and portfolio calculations
  • Sentiment Service: Analyzes news and generates sentiment scores
  • Data Service: Collects and manages market data
  • Recommendation Service: Generates AI-powered trading suggestions
  • Market Scanner: Discovers trending stocks from news
  • Scheduler Service: Manages automated data collection

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.9+
  • Node.js 18+
  • Docker (optional)
  • Git

Option 1: Complete Setup (Recommended)

For first-time setup with Google OAuth and all features:

๐Ÿ‘‰ Follow the Development Setup Guide for step-by-step instructions.

Option 2: Basic Demo (Quick Test)

# Clone the repository
git clone https://github.com/yourusername/trading-platform.git
cd trading-platform

# Start backend
cd backend
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows
pip install -r requirements.txt
python main.py

# Start frontend (new terminal)
cd frontend
npm install
npm start

# Visit http://localhost:3000

Note: For Google OAuth login to work, you'll need to configure Google Cloud credentials. See Google OAuth Setup Guide.

Need Help?

๐Ÿ“ฆ Installation

Backend Setup

cd backend

# Create virtual environment
python -m venv trading_env
source trading_env/bin/activate  # Windows: trading_env\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env with your settings

# Initialize database
python -c "from database import Base, engine; Base.metadata.create_all(bind=engine)"

# Start the API server
python main.py

Frontend Setup

cd frontend

# Install dependencies
npm install

# Configure environment
cp .env.example .env.local
# Edit .env.local with your settings

# Start development server
npm start

๐ŸŽฎ Usage

Basic Trading Workflow

  1. Start the Application

    # Terminal 1: Backend
    cd backend && python main.py
    
    # Terminal 2: Frontend  
    cd frontend && npm start
  2. Access the Dashboard

    • Open http://localhost:3000
    • View portfolio performance and recent trades
    • Monitor sentiment analysis results
  3. Execute Trades

    • Navigate to "Trading" section
    • Enter stock symbol, quantity, and trade type
    • Submit paper trade (uses real market prices)
  4. Run Sentiment Analysis

    # Manual analysis
    curl -X POST http://localhost:8000/api/analyze-sentiment -d '{"symbol": "AAPL"}'
    
    # Bulk analysis
    curl -X POST http://localhost:8000/api/analyze-bulk-sentiment \
      -d '{"symbols": ["AAPL", "MSFT", "GOOGL"]}'
  5. Automated Data Collection

    # Run the scheduler for automated updates
    cd backend
    python scheduler.py

Advanced Features

Market Discovery

# Scan for trending stocks
curl -X POST http://localhost:8000/api/market-scan

# Auto-discover and analyze
curl -X POST http://localhost:8000/api/auto-discover

# Full discovery pipeline
curl -X POST http://localhost:8000/api/discovery-to-recommendations

Strategy Execution

# Run sentiment-based trading strategy
curl -X POST http://localhost:8000/api/run-strategy

๐Ÿ“š API Documentation

Core Endpoints

Trading

  • GET /api/trades - List all trades
  • POST /api/trades - Create new trade
  • POST /api/trades/{id}/close - Close existing trade
  • DELETE /api/trades/{id} - Delete trade

Portfolio

  • GET /api/performance - Portfolio metrics and P&L
  • GET /api/portfolio-history - Historical portfolio values

Sentiment

  • GET /api/sentiment - All sentiment data
  • GET /api/sentiment/{symbol} - Symbol-specific sentiment
  • POST /api/analyze-sentiment - Trigger analysis

Market Data

  • GET /api/stocks - Tracked stocks
  • POST /api/stocks - Add stock to tracking
  • GET /api/market-data/{symbol} - Historical market data

For complete API documentation, see Backend API Documentation.

โš™๏ธ Configuration

Environment Variables

Backend Configuration (.env)

# Database
DATABASE_URL=sqlite:///trading.db

# Trading Settings
INITIAL_BALANCE=100000.0
MAX_POSITION_SIZE=0.05

# Market Hours
MARKET_OPEN_TIME=09:30
MARKET_CLOSE_TIME=16:00

# API Keys (Optional)
NEWS_API_KEY=your_news_api_key
ALPHA_VANTAGE_KEY=your_alpha_vantage_key

# CORS
CORS_ORIGINS=["http://localhost:3000"]

Frontend Configuration (.env.local)

REACT_APP_API_URL=http://localhost:8000

Scheduler Configuration

The scheduler automatically runs:

  • Market data collection at market open
  • Hourly data updates during trading hours
  • Daily sentiment analysis at 10:00 AM
  • Strategy execution at 10:30 AM
  • End-of-day collection at market close

๐Ÿ› ๏ธ Development

Backend Development

cd backend

# Install development dependencies
pip install -r requirements-dev.txt

# Run with auto-reload
uvicorn main:app --reload --host 0.0.0.0 --port 8000

# Run tests
python -m pytest tests/

# Code formatting
black .
isort .

Frontend Development

cd frontend

# Install development dependencies
npm install

# Start with hot reload
npm start

# Run tests
npm test

# Build for production
npm run build

Database Management

# Reset database
rm backend/trading.db
python -c "from database import Base, engine; Base.metadata.create_all(bind=engine)"

# View database schema
sqlite3 backend/trading.db ".schema"

๐Ÿงช Testing

Backend Tests

cd backend

# Run all tests
python -m pytest

# Run with coverage
python -m pytest --cov=.

# Run specific test files
python test_workflow.py
python test_frontend_apis.py

Frontend Tests

cd frontend

# Run tests
npm test

# Run with coverage
npm test -- --coverage

API Testing

# Test workflow script
cd backend
python test_workflow.py

# Test frontend APIs
python test_frontend_apis.py

๐Ÿ“ Project Structure

trading-platform/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application
โ”‚   โ”œโ”€โ”€ scheduler.py         # Background data scheduler
โ”‚   โ”œโ”€โ”€ config.py           # Configuration management
โ”‚   โ”œโ”€โ”€ database.py         # Database setup
โ”‚   โ”œโ”€โ”€ models.py           # SQLAlchemy models
โ”‚   โ”œโ”€โ”€ schemas.py          # Pydantic schemas
โ”‚   โ”œโ”€โ”€ exceptions.py       # Custom exceptions
โ”‚   โ”œโ”€โ”€ services/           # Business logic
โ”‚   โ”‚   โ”œโ”€โ”€ trading_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ sentiment_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ data_service.py
โ”‚   โ”‚   โ”œโ”€โ”€ recommendation_service.py
โ”‚   โ”‚   โ””โ”€โ”€ market_scanner.py
โ”‚   โ”œโ”€โ”€ docs/               # Backend documentation
โ”‚   โ”œโ”€โ”€ tests/              # Test files
โ”‚   โ””โ”€โ”€ requirements.txt
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/     # React components
โ”‚   โ”‚   โ”œโ”€โ”€ pages/          # Page components
โ”‚   โ”‚   โ”œโ”€โ”€ services/       # API integration
โ”‚   โ”‚   โ””โ”€โ”€ App.js
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ tailwind.config.js
โ””โ”€โ”€ docs/                   # Project documentation

๐Ÿ” Authentication

The platform uses Google OAuth for secure user authentication:

  1. Setup Google OAuth:

    • Create a Google Cloud project
    • Enable Google+ API
    • Create OAuth 2.0 credentials
    • Add your domain to authorized origins
  2. Configure Environment:

    # Backend (.env)
    GOOGLE_CLIENT_ID=your_google_client_id_here.apps.googleusercontent.com
    JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
    
    # Frontend (.env.local)
    REACT_APP_GOOGLE_CLIENT_ID=your_google_client_id_here.apps.googleusercontent.com
  3. Features:

    • Secure JWT-based session management
    • Automatic token refresh
    • Protected routes and API endpoints
    • User profile integration

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™‹ Support

  • ๐Ÿ“š Documentation: Check the /docs folder and service-specific READMEs
  • ๐Ÿ› Issues: Report technical issues or bugs
  • ๐Ÿ“ง Contact: For business inquiries and support

๐Ÿ”ฎ Roadmap

  • Real trading integration (Alpaca, Interactive Brokers)
  • Advanced technical indicators
  • Machine learning models for prediction
  • Mobile application
  • User authentication with Google OAuth
  • Advanced portfolio analytics
  • Options trading support
  • Real-time WebSocket updates
  • Subscription-based SaaS features

โš ๏ธ Disclaimer: This is a paper trading platform for educational purposes only. Past performance does not guarantee future results. Always consult with financial professionals before making real investment decisions.

About

Complete Trading Platform with AWS deployment automation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •