Skip to content

GridTrader Pro - Systematic Investment Management Platform with Grid Trading Algorithms, Portfolio Management, and Real-time Market Data

Notifications You must be signed in to change notification settings

SDG223157/gridtrader-pro-webapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GridTrader Pro - Systematic Investment Management Platform

A comprehensive investment management platform featuring grid trading algorithms, portfolio rebalancing, and real-time market data integration. Built with Python FastAPI and HTML templates for deployment with Docker.

πŸš€ Features

  • Grid Trading Algorithms with dynamic spacing and risk management
  • Portfolio Management with automated rebalancing and performance tracking
  • Real-time Market Data via yfinance integration with technical indicators
  • Google OAuth Authentication with JWT tokens for secure access
  • Background Data Processing with Celery for automated updates
  • Responsive Web Interface with modern HTML/CSS/JavaScript
  • Production-Ready Docker Deployment with single container architecture
  • πŸ€– AI Integration with MCP (Model Context Protocol) for Cursor IDE
  • Natural Language Trading - Control your portfolios with plain English commands

πŸ“‹ Tech Stack

  • Backend: FastAPI (Python 3.11+)
  • Database: MySQL 8.0+ with SQLAlchemy ORM
  • Authentication: Google OAuth 2.0 + JWT
  • Data Source: yfinance (Yahoo Finance) - FREE
  • Frontend: HTML5 + TailwindCSS + Alpine.js
  • Background Tasks: Celery + Redis
  • Deployment: Docker + Nginx + Supervisor
  • Charts: Chart.js + Plotly.js

πŸ—οΈ Architecture

GridTrader Pro WebApp/
β”œβ”€β”€ main.py                 # FastAPI application
β”œβ”€β”€ database.py             # Database models and connection
β”œβ”€β”€ auth.py                 # Authentication system
β”œβ”€β”€ data_provider.py        # yfinance integration
β”œβ”€β”€ tasks.py                # Celery background tasks
β”œβ”€β”€ app/
β”‚   └── algorithms/
β”‚       └── grid_trading.py # Trading algorithms
β”œβ”€β”€ templates/              # HTML templates
β”‚   β”œβ”€β”€ base.html          # Base template
β”‚   β”œβ”€β”€ index.html         # Homepage
β”‚   β”œβ”€β”€ dashboard.html     # Main dashboard
β”‚   β”œβ”€β”€ portfolios.html    # Portfolio management
β”‚   β”œβ”€β”€ grids.html         # Grid trading interface
β”‚   └── partials/          # Template components
β”œβ”€β”€ static/                # Static assets (CSS, JS, images)
β”œβ”€β”€ docker/                # Docker configuration
β”‚   β”œβ”€β”€ start.sh           # Startup script
β”‚   β”œβ”€β”€ supervisord.conf   # Process management
β”‚   └── nginx.conf         # Web server config
β”œβ”€β”€ Dockerfile             # Container definition
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ .env.example          # Environment configuration
└── README.md

πŸ› οΈ Quick Start

1. Clone and Setup

git clone <repository-url>
cd gridtrader-pro-webapp
cp .env.example .env

2. Configure Environment

Edit .env file with your configuration:

# Database
DB_HOST=your-mysql-host
DB_PASSWORD=your-mysql-password
DB_NAME=gridtrader_db

# Google OAuth
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret

# Security
SECRET_KEY=your-super-secret-key-32-chars-minimum

# Redis
REDIS_HOST=your-redis-host
REDIS_PASSWORD=your-redis-password

3. Build and Run

# Build Docker image
docker build -t gridtrader-pro .

# Run with environment file
docker run -d \
  --name gridtrader-pro \
  --env-file .env \
  -p 3000:3000 \
  gridtrader-pro

4. Access Application

πŸ”§ Development Setup

Local Development

# Install dependencies
pip install -r requirements.txt

# Start Redis (required for background tasks)
redis-server

# Run database migrations
python -c "from database import create_tables; create_tables()"

# Start the application
python main.py

# In another terminal, start Celery worker
celery -A tasks worker --loglevel=info

# In another terminal, start Celery beat (scheduler)
celery -A tasks beat --loglevel=info

Docker Compose (Recommended for Development)

version: '3.8'
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - DB_HOST=mysql
      - REDIS_HOST=redis
    depends_on:
      - mysql
      - redis
    
  mysql:
    image: mysql:8.0
    environment:
      - MYSQL_DATABASE=gridtrader_db
      - MYSQL_ROOT_PASSWORD=rootpassword
    
  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes

πŸ“Š Key Features

Grid Trading

  • Dynamic Grid Spacing: Automatically adjusts based on market volatility
  • Risk Management: Built-in stop-loss and position sizing
  • Backtesting: Historical performance analysis
  • Multiple Strategies: Standard, Dynamic, and Martingale grids

Portfolio Management

  • Real-time Tracking: Live portfolio values and P&L
  • Auto-rebalancing: Maintains target allocations
  • Performance Analytics: Returns, Sharpe ratio, drawdown analysis
  • Multi-strategy Support: Grid trading, core-satellite, balanced growth

Market Data

  • Real-time Prices: Live data from Yahoo Finance
  • Technical Indicators: SMA, EMA, RSI, MACD, Bollinger Bands
  • Historical Data: Complete price history with OHLCV
  • Symbol Search: Find and validate trading symbols

Background Processing

  • Market Data Updates: Every 5 minutes during market hours
  • Portfolio Revaluation: Every 10 minutes
  • Grid Order Processing: Every 3 minutes
  • Alert Generation: Price movements and portfolio changes
  • Data Cleanup: Automatic cleanup of old data

πŸ” Security Features

  • Google OAuth 2.0: Secure authentication with JWT tokens
  • HTTPS/SSL: Required for production deployment
  • CORS Protection: Configurable allowed origins
  • Rate Limiting: API endpoint protection
  • Secure Sessions: HTTP-only cookies with proper expiration
  • Input Validation: Comprehensive request validation
  • SQL Injection Protection: Parameterized queries with SQLAlchemy

πŸ“ˆ API Endpoints

Authentication

  • GET /login - Login page
  • POST /api/auth/login - Email/password login
  • GET /api/auth/google - Google OAuth login
  • POST /logout - Logout

Portfolios

  • GET /portfolios - List portfolios
  • POST /api/portfolios - Create portfolio
  • GET /api/portfolios/{id} - Get portfolio details
  • PUT /api/portfolios/{id} - Update portfolio
  • DELETE /api/portfolios/{id} - Delete portfolio

Grid Trading

  • GET /grids - List grids
  • POST /api/grids - Create grid
  • GET /api/grids/{id} - Get grid details
  • PUT /api/grids/{id} - Update grid
  • DELETE /api/grids/{id} - Delete grid

Market Data

  • GET /api/market/{symbol} - Get symbol data
  • GET /api/search/symbols?q={query} - Search symbols

πŸš€ Deployment

Coolify Deployment (Recommended)

  1. Create new service in Coolify
  2. Set repository: Point to your Git repository
  3. Configure build: Use the provided Dockerfile
  4. Set environment variables: Copy from .env.example
  5. Deploy: Coolify handles the rest automatically

Manual Docker Deployment

# Build and tag image
docker build -t gridtrader-pro:latest .

# Run with proper environment
docker run -d \
  --name gridtrader-pro \
  --restart unless-stopped \
  --env-file .env \
  -p 3000:3000 \
  gridtrader-pro:latest

Environment Variables

Variable Description Required
DB_HOST MySQL host βœ…
DB_PASSWORD MySQL password βœ…
DB_NAME Database name βœ…
GOOGLE_CLIENT_ID OAuth client ID βœ…
GOOGLE_CLIENT_SECRET OAuth secret βœ…
SECRET_KEY JWT secret key βœ…
REDIS_HOST Redis host βœ…
FRONTEND_URL Application URL βœ…
LOG_LEVEL Logging level ❌

πŸ“Š Monitoring

Health Checks

  • Application: GET /health
  • Database: Connection test in health endpoint
  • Redis: Connection test in health endpoint
  • Docker: Built-in healthcheck with curl

Logging

  • Application Logs: /app/logs/app.log
  • Celery Worker: /app/logs/celery.log
  • Celery Beat: /app/logs/celery-beat.log
  • Nginx Access: /var/log/nginx/access.log
  • Nginx Error: /var/log/nginx/error.log

Metrics

  • Portfolio performance tracking
  • Grid trading success rates
  • API response times
  • Background task execution times

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

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

πŸ€– AI Integration (MCP)

GridTrader Pro supports AI-powered portfolio management through Cursor IDE:

Quick Setup

# Install MCP server globally
./install-mcp-global.sh

# Or manually:
npm install -g gridtrader-pro-mcp

Configuration

  1. Create API token at: https://your-domain.com/tokens
  2. Add MCP config to Cursor settings
  3. Restart Cursor
  4. Use natural language: "Show me my portfolios"

πŸ“– Complete Guide: See GLOBAL_MCP_SETUP_GUIDE.md

Example AI Commands

  • "Show me my cash balances"
  • "Create a growth portfolio with $25,000"
  • "Set up a grid for AAPL between $150-200"
  • "What's my portfolio performance?"
  • "Update my cash balance to reflect interest earned"

πŸ†˜ Support

For deployment issues:

  1. Check the logs in /app/logs/
  2. Verify environment variables are set correctly
  3. Test the health endpoint: /health
  4. Ensure database and Redis connectivity
  5. Review Docker container logs

For MCP integration issues:

  1. Check API token validity: /tokens page
  2. Verify MCP server installation: gridtrader-pro-mcp --version
  3. Test API connectivity: curl -H "Authorization: Bearer TOKEN" https://your-domain.com/api/portfolios
  4. Review Cursor MCP logs: Cursor Developer Tools

🎯 Roadmap

  • WebSocket real-time updates
  • Advanced backtesting interface
  • More trading strategies
  • Mobile-responsive improvements
  • API rate limiting
  • Advanced charting features
  • Export/import functionality
  • Multi-language support

Ready for production deployment with Docker! πŸš€

About

GridTrader Pro - Systematic Investment Management Platform with Grid Trading Algorithms, Portfolio Management, and Real-time Market Data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published