Skip to content

Latest commit

Β 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Trade Paper - Paper Trading Platform

A full-stack web application for paper trading with real-time market data, advanced charting, and portfolio management features.

Status Python Node.js License


πŸ“‹ Table of Contents


Overview

Trade Paper is a comprehensive paper trading platform that allows users to practice trading strategies with real-time market data without risking actual capital. The application features professional-grade charting, real-time market data from Yahoo Finance, stop-loss monitoring, and a responsive interface designed for desktop and mobile devices.

Key Highlights

  • πŸ“Š Professional Charts - Full-screen candlestick and line charts with Lightweight Charts & Recharts
  • 🎯 Stop Loss Monitoring - Real-time monitoring with Celery background tasks
  • πŸ’Ή Live Market Data - Real-time data from Yahoo Finance API
  • πŸ” Secure Authentication - JWT-based user authentication
  • πŸ“± Responsive Design - Works seamlessly on mobile, tablet, and desktop
  • ⚑ Fast & Scalable - Built with modern async frameworks and task queues

Features

🎯 Core Features

  • Real-Time Charts

    • Candlestick charts for technical analysis
    • Line charts for historical trend analysis
    • Full-screen display capability
    • Professional styling with smooth animations
  • Market Data Integration

    • Real-time ticker data from Yahoo Finance
    • Historical price data
    • Market indicators and technical analysis
    • Multi-ticker support
  • Portfolio Management

    • Track paper trades
    • Stop-loss monitoring
    • Position management
    • Trade history
  • User Management

    • Secure registration and login
    • JWT token-based authentication
    • User profiles
    • Portfolio tracking
  • Responsive Design

    • Mobile optimization (< 480px)
    • Tablet support (480-768px)
    • Desktop layout (> 768px)
    • Large screen support (> 1024px)

πŸ”„ Background Processing

  • Celery worker for async task processing
  • Celery Beat for scheduled tasks
  • Real-time stop-loss monitoring
  • Task queue management

πŸ“Š Monitoring & Management

  • Flower dashboard for task monitoring
  • Django admin interface
  • Redis for caching and message brokering
  • Comprehensive logging

Tech Stack

Backend

  • Framework: Django 5.2.4 + Django REST Framework
  • API: FastAPI 0.115.0
  • Authentication: JWT (djangorestframework-simplejwt)
  • Task Queue: Celery 5.4.0 + Celery Beat
  • Message Broker: Redis 6.2.0
  • Real-Time: Channels 4.2.2 + Channels Redis
  • Database: PostgreSQL / SQLite (development)
  • Data Processing: Pandas 2.2.0
  • Market Data: Yahoo Finance (via yfinance)

Frontend

  • Framework: React 18.2.0
  • Build Tool: Vite 5.0.0
  • Router: React Router v6
  • HTTP Client: Axios
  • Charting: Lightweight Charts 4.2.1 + Recharts 2.12.7
  • Icons: Lucide React
  • CSS: Custom CSS with responsive design

DevOps & Tools

  • Task Monitoring: Flower 2.0.1
  • CORS: django-cors-headers
  • Environment: python-decouple, python-dotenv
  • WebSockets: Uvicorn with Websockets support

Quick Start

Prerequisites

  • Python: 3.9 or higher
  • Node.js: 18 or higher
  • Redis: Running locally or in Docker
  • Git: For version control

5-Minute Setup

# 1. Clone and navigate to project
git clone <repository-url>
cd trade_paper

# 2. Setup Python environment
python -m venv venv
venv\Scripts\activate  # Windows
# or source venv/bin/activate  # Linux/Mac

# 3. Install Python dependencies
pip install -r requirements.txt

# 4. Setup frontend
cd frontend
npm install
cd ..

# 5. Start Redis
# Docker: docker run -d -p 6379:6379 redis:latest
# Or native installation: redis-server

# 6. Run migrations
cd backend
python manage.py migrate
cd ..

# 7. Start all services (see Running the Application section)

Project Structure

trade_paper/
β”œβ”€β”€ backend/                          # Django + FastAPI backend
β”‚   β”œβ”€β”€ main/                         # Main app with core logic
β”‚   β”‚   β”œβ”€β”€ models.py                 # Database models
β”‚   β”‚   β”œβ”€β”€ views.py                  # API views
β”‚   β”‚   β”œβ”€β”€ serializers.py            # DRF serializers
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── market.py             # Market data service
β”‚   β”‚   β”œβ”€β”€ tasks.py                  # Celery tasks
β”‚   β”‚   └── urls.py                   # URL routing
β”‚   β”œβ”€β”€ accounts/                     # User authentication
β”‚   β”‚   β”œβ”€β”€ models.py                 # User model
β”‚   β”‚   β”œβ”€β”€ views.py                  # Auth endpoints
β”‚   β”‚   └── serializers.py            # Auth serializers
β”‚   β”œβ”€β”€ tickers/                      # Ticker data (FastAPI)
β”‚   β”‚   β”œβ”€β”€ app.py                    # FastAPI app
β”‚   β”‚   └── data/                     # Data files
β”‚   β”œβ”€β”€ trade_paper/                  # Project settings
β”‚   β”‚   β”œβ”€β”€ settings.py               # Django settings
β”‚   β”‚   β”œβ”€β”€ urls.py                   # Main URL config
β”‚   β”‚   β”œβ”€β”€ wsgi.py                   # WSGI config
β”‚   β”‚   β”œβ”€β”€ asgi.py                   # ASGI config (WebSockets)
β”‚   β”‚   └── celery.py                 # Celery configuration
β”‚   β”œβ”€β”€ manage.py                     # Django management
β”‚   β”œβ”€β”€ main.py                       # FastAPI entry point
β”‚   └── db.sqlite3                    # Development database
β”‚
β”œβ”€β”€ frontend/                         # React + Vite frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/               # React components
β”‚   β”‚   β”œβ”€β”€ pages/                    # Page components
β”‚   β”‚   β”œβ”€β”€ api/                      # API client
β”‚   β”‚   β”œβ”€β”€ context/                  # React context
β”‚   β”‚   β”œβ”€β”€ hooks/                    # Custom hooks
β”‚   β”‚   β”œβ”€β”€ services/                 # Services
β”‚   β”‚   β”œβ”€β”€ styles/                   # Global styles
β”‚   β”‚   β”œβ”€β”€ App.jsx                   # Main component
β”‚   β”‚   └── main.jsx                  # Entry point
β”‚   β”œβ”€β”€ public/                       # Static assets
β”‚   β”œβ”€β”€ package.json                  # NPM dependencies
β”‚   β”œβ”€β”€ vite.config.js                # Vite configuration
β”‚   └── index.html                    # HTML template
β”‚
β”œβ”€β”€ _MD/                              # Documentation
β”‚   β”œβ”€β”€ QUICK_START.md                # Quick setup guide
β”‚   β”œβ”€β”€ DELIVERY_SUMMARY.md           # Project delivery summary
β”‚   β”œβ”€β”€ CHART_ENHANCEMENT_GUIDE.md    # Chart features
β”‚   β”œβ”€β”€ STOP_LOSS_IMPLEMENTATION.md   # Stop loss logic
β”‚   β”œβ”€β”€ TICKER_DETAIL_IMPLEMENTATION.md # Ticker details
β”‚   └── ...                           # More documentation
β”‚
β”œβ”€β”€ requirements.txt                  # Python dependencies
β”œβ”€β”€ package.json                      # Root package config
β”œβ”€β”€ README.md                         # This file
└── pyvenv.cfg                        # Virtual env config

Installation

Backend Setup

# 1. Navigate to project root
cd trade_paper

# 2. Create virtual environment
python -m venv venv
venv\Scripts\activate

# 3. Install Python dependencies
pip install -r requirements.txt

# 4. Create .env file (optional)
# Add environment variables as needed
echo DEBUG=True > backend/.env

# 5. Setup database
cd backend
python manage.py migrate
python manage.py createsuperuser  # Create admin user
cd ..

Frontend Setup

# 1. Navigate to frontend
cd frontend

# 2. Install dependencies
npm install

# 3. Create .env file if needed
# Add API endpoint configuration

# 4. Build for production (optional)
npm run build

# 5. Return to root
cd ..

Redis Setup

Option 1: Docker (Recommended)

docker run -d --name trade-paper-redis -p 6379:6379 redis:latest

Option 2: Windows Native

# Download from https://github.com/microsoftarchive/redis/releases
# Install and run
"C:\Program Files\Redis\redis-server.exe"

Option 3: WSL

wsl redis-server

Running the Application

Start Services (6 Terminals)

Terminal 1: Redis Server

# Docker
docker start trade-paper-redis

# OR native/WSL
redis-server

Terminal 2: Django API Server

cd backend
python manage.py runserver
# Runs on http://localhost:8000

Terminal 3: Celery Worker

cd backend
celery -A trade_paper worker -l info

Terminal 4: Celery Beat (Scheduler)

cd backend
celery -A trade_paper beat -l info

Terminal 5: React Frontend

cd frontend
npm run dev
# Runs on http://localhost:5173

Terminal 6 (Optional): Flower Monitoring

cd backend
flower -A trade_paper --port=5555
# Dashboard at http://localhost:5555

Service URLs

Service URL Purpose
Frontend http://localhost:5173 React application
Django API http://localhost:8000 REST API
Admin Panel http://localhost:8000/admin Django admin
Flower Dashboard http://localhost:5555 Task monitoring
Redis localhost:6379 Message broker

Verify Everything is Running

# Test Redis
redis-cli ping
# Output: PONG

# Test Django API
curl http://localhost:8000/api/health
# Should return success

# Check Celery
curl http://localhost:5555  # Opens Flower dashboard

# Check Frontend
# Open http://localhost:5173 in browser

API Documentation

Authentication Endpoints

User Registration

POST /api/accounts/register/
Content-Type: application/json

{
  "username": "string",
  "email": "string",
  "password": "string"
}

User Login

POST /api/accounts/login/
{
  "username": "string",
  "password": "string"
}

Response:
{
  "access": "token",
  "refresh": "token"
}

Market Data Endpoints

Get Ticker Information

GET /api/main/ticker/<symbol>/

Get Historical Data

GET /api/main/ticker/<symbol>/history/?period=1mo

Get Real-Time Prices

GET /api/main/ticker/<symbol>/price/

Portfolio Endpoints

Get User Portfolio

GET /api/main/portfolio/

Create Trade

POST /api/main/trades/
{
  "symbol": "AAPL",
  "quantity": 10,
  "price": 150.50,
  "trade_type": "BUY"
}

Set Stop Loss

POST /api/main/trades/<id>/set-stop-loss/
{
  "stop_price": 140.00
}

Configuration

Django Settings

Located at backend/trade_paper/settings.py

Key Settings:

  • DEBUG - Set to False in production
  • ALLOWED_HOSTS - Configure for your domain
  • DATABASES - Database configuration
  • CELERY_BROKER_URL - Redis URL (default: redis://localhost:6379)
  • CORS_ALLOWED_ORIGINS - Frontend URL for CORS

Environment Variables

Create backend/.env:

DEBUG=False
SECRET_KEY=your-secret-key
DATABASE_URL=postgresql://user:password@localhost/tradepaper
REDIS_URL=redis://localhost:6379
ALLOWED_HOSTS=localhost,127.0.0.1,yourdomain.com

Frontend Configuration

Create frontend/.env:

VITE_API_URL=http://localhost:8000/api
VITE_WS_URL=ws://localhost:8000

Development

Code Style

The project follows:

  • Backend: PEP 8 (Python)
  • Frontend: ESLint configuration (JavaScript/React)

Running Tests

# Backend tests
cd backend
python manage.py test

# Frontend tests
cd frontend
npm test

Adding New Features

  1. Backend API:

    • Create model in main/models.py
    • Create serializer in main/serializers.py
    • Add endpoint in main/views.py
    • Register URL in main/urls.py
  2. Frontend:

    • Create component in frontend/src/components/
    • Add page in frontend/src/pages/
    • Register route in App.jsx
  3. Database Migrations:

    cd backend
    python manage.py makemigrations
    python manage.py migrate

Debugging

Django Debugging:

# In views.py
import logging
logger = logging.getLogger(__name__)
logger.debug("Debug message")

Celery Task Debugging:

# Run worker with debug logging
celery -A trade_paper worker -l debug

React Debugging:

  • Use React DevTools browser extension
  • Check browser console for errors
  • Use console.log() or debugger breakpoints

Testing

Manual Testing Checklist

Charts:

  • Candlestick chart displays correctly
  • Line chart displays correctly
  • Full-screen mode works
  • Charts responsive on mobile
  • Chart switching works smoothly

Authentication:

  • User registration works
  • Login/logout functions
  • JWT tokens refreshed correctly
  • Protected routes require authentication

Market Data:

  • Real-time prices update
  • Historical data loads
  • Multiple tickers work
  • Data refreshes periodically

Stop Loss:

  • Stop loss can be set
  • Alerts trigger at threshold
  • Monitoring works continuously

Deployment

Production Checklist

# 1. Set production environment
export DEBUG=False
export SECRET_KEY=<generate-strong-key>

# 2. Collect static files
cd backend
python manage.py collectstatic --noinput

# 3. Run migrations
python manage.py migrate --noinput

# 4. Build frontend
cd ../frontend
npm run build

# 5. Run with production server
cd ../backend
gunicorn trade_paper.wsgi:application --workers 4

Deployment Options

  • Heroku: Use Procfile and buildpacks
  • AWS: EC2 with RDS, ElastiCache for Redis
  • Docker: Containerize with Docker Compose
  • PythonAnywhere: Simple Python hosting
  • Digital Ocean: App Platform or Droplet

Troubleshooting

Common Issues

Issue: "Connection refused" to Redis

Solution: Ensure Redis is running
docker ps  # Check if Redis container is running
redis-cli ping  # Test Redis connection

Issue: Celery tasks not processing

Solution: 
1. Verify Redis is running
2. Check Celery worker logs
3. Verify CELERY_BROKER_URL in settings

Issue: CORS errors in frontend

Solution:
1. Add frontend URL to CORS_ALLOWED_ORIGINS
2. Check browser console for specific error
3. Verify API_URL in frontend .env

Issue: Database migrations fail

Solution:
cd backend
python manage.py migrate --run-syncdb  # Recreate all tables

Issue: Frontend won't connect to API

Solution:
1. Verify Django server is running (http://localhost:8000)
2. Check VITE_API_URL in frontend/.env
3. Test API endpoint: curl http://localhost:8000/api/

Getting Help

  • Check the _MD/ folder for detailed documentation
  • Review Django/React documentation
  • Check Celery/Redis logs
  • Use Flower dashboard to monitor tasks

Documentation

Comprehensive documentation is available in the _MD/ folder:


Contributing

Development Workflow

  1. Fork or clone the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Make your changes with clear commit messages
  4. Test your changes: npm test (frontend) / python manage.py test (backend)
  5. Push to branch: git push origin feature/your-feature
  6. Create a Pull Request with description

Commit Message Convention

[BACKEND/FRONTEND] Feature: Brief description
- Details of change
- Details of change

Fixes #issue-number

License

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


Support & Contact

For issues, questions, or suggestions:

  • πŸ“§ Email: support@tradepaper.app
  • πŸ› Issues: GitHub Issues
  • πŸ’¬ Discussions: GitHub Discussions
  • πŸ“š Docs: See _MD/ folder

Acknowledgments

Built with:

  • Django & Django REST Framework
  • React & Vite
  • Lightweight Charts & Recharts
  • Yahoo Finance API
  • Redis & Celery
  • PostgreSQL

Last Updated: May 31, 2026
Status: Production Ready βœ…
Version: 1.0.0

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages