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.
- 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
- 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
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
git clone <repository-url>
cd gridtrader-pro-webapp
cp .env.example .env
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
# 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
- Web Interface: http://localhost:3000
- API Documentation: http://localhost:3000/docs
- Health Check: http://localhost:3000/health
# 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
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
- 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
- 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
- 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
- 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
- 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
GET /login
- Login pagePOST /api/auth/login
- Email/password loginGET /api/auth/google
- Google OAuth loginPOST /logout
- Logout
GET /portfolios
- List portfoliosPOST /api/portfolios
- Create portfolioGET /api/portfolios/{id}
- Get portfolio detailsPUT /api/portfolios/{id}
- Update portfolioDELETE /api/portfolios/{id}
- Delete portfolio
GET /grids
- List gridsPOST /api/grids
- Create gridGET /api/grids/{id}
- Get grid detailsPUT /api/grids/{id}
- Update gridDELETE /api/grids/{id}
- Delete grid
GET /api/market/{symbol}
- Get symbol dataGET /api/search/symbols?q={query}
- Search symbols
- Create new service in Coolify
- Set repository: Point to your Git repository
- Configure build: Use the provided
Dockerfile
- Set environment variables: Copy from
.env.example
- Deploy: Coolify handles the rest automatically
# 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
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 | β |
- Application:
GET /health
- Database: Connection test in health endpoint
- Redis: Connection test in health endpoint
- Docker: Built-in healthcheck with curl
- 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
- Portfolio performance tracking
- Grid trading success rates
- API response times
- Background task execution times
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
GridTrader Pro supports AI-powered portfolio management through Cursor IDE:
# Install MCP server globally
./install-mcp-global.sh
# Or manually:
npm install -g gridtrader-pro-mcp
- Create API token at:
https://your-domain.com/tokens
- Add MCP config to Cursor settings
- Restart Cursor
- Use natural language: "Show me my portfolios"
π Complete Guide: See GLOBAL_MCP_SETUP_GUIDE.md
- "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"
For deployment issues:
- Check the logs in
/app/logs/
- Verify environment variables are set correctly
- Test the health endpoint:
/health
- Ensure database and Redis connectivity
- Review Docker container logs
For MCP integration issues:
- Check API token validity:
/tokens
page - Verify MCP server installation:
gridtrader-pro-mcp --version
- Test API connectivity:
curl -H "Authorization: Bearer TOKEN" https://your-domain.com/api/portfolios
- Review Cursor MCP logs: Cursor Developer Tools
- 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! π