6.8 KiB
6.8 KiB
Web Architecture Deployment Guide
This guide covers deploying the new web-based architecture for Crypto Trader.
Overview
The application has been migrated from PyQt6 desktop app to a modern web-based architecture:
- Frontend: React + TypeScript + Material-UI
- Backend: FastAPI (Python)
- Deployment: Docker
Architecture
┌─────────────────────────────────────────┐
│ Web Browser (Client) │
│ React + Material-UI + TypeScript │
└─────────────────┬───────────────────────┘
│ HTTP/WebSocket
┌─────────────────▼───────────────────────┐
│ Python Backend API (FastAPI) │
│ - Trading Engine (existing code) │
│ - Strategy Framework (existing code) │
│ - Portfolio Management (existing code) │
└─────────────────┬───────────────────────┘
│
┌─────────────────▼───────────────────────┐
│ Database (SQLite/PostgreSQL) │
└─────────────────────────────────────────┘
Quick Start
Development
-
Start Backend:
cd backend python -m uvicorn main:app --reload --port 8000 -
Start Frontend:
cd frontend npm install npm run dev -
Access Application:
- Frontend: http://localhost:3000
- API Docs: http://localhost:8000/docs
- API: http://localhost:8000/api
Docker Deployment
-
Build and Run:
docker-compose up --build -
Access Application:
- Application: http://localhost:8000
- API Docs: http://localhost:8000/docs
API Endpoints
Trading
POST /api/trading/orders- Create orderGET /api/trading/orders- List ordersGET /api/trading/orders/{id}- Get orderPOST /api/trading/orders/{id}/cancel- Cancel orderGET /api/trading/positions- Get positionsGET /api/trading/balance- Get balance
Portfolio
GET /api/portfolio/current- Get current portfolioGET /api/portfolio/history- Get portfolio historyPOST /api/portfolio/positions/update-prices- Update prices
Strategies
GET /api/strategies/- List strategiesGET /api/strategies/available- List available strategy typesPOST /api/strategies/- Create strategyGET /api/strategies/{id}- Get strategyPUT /api/strategies/{id}- Update strategyDELETE /api/strategies/{id}- Delete strategyPOST /api/strategies/{id}/start- Start strategyPOST /api/strategies/{id}/stop- Stop strategy
Backtesting
POST /api/backtesting/run- Run backtestGET /api/backtesting/results/{id}- Get backtest results
Exchanges
GET /api/exchanges/- List exchangesGET /api/exchanges/{id}- Get exchange
WebSocket
WS /ws/- WebSocket connection for real-time updates
Configuration
Environment Variables
Create .env file:
# API Configuration
VITE_API_URL=http://localhost:8000
VITE_WS_URL=ws://localhost:8000/ws/
# Database (optional)
DATABASE_URL=sqlite:///./data/crypto_trader.db
Docker Environment
Environment variables can be set in docker-compose.yml:
environment:
- DATABASE_URL=sqlite:///./data/crypto_trader.db
- PYTHONPATH=/app
Data Persistence
Data is stored in the ./data directory, which is mounted as a volume in Docker:
volumes:
- ./data:/app/data
Development
Backend Development
-
Install dependencies:
pip install -r requirements.txt pip install -r backend/requirements.txt -
Run with hot-reload:
python -m uvicorn backend.main:app --reload
Frontend Development
-
Install dependencies:
cd frontend npm install -
Run development server:
npm run dev -
Build for production:
npm run build
Production Deployment
Docker Production
-
Build production image:
docker build -t crypto-trader:latest . -
Run container:
docker run -d \ -p 8000:8000 \ -v $(pwd)/data:/app/data \ -v $(pwd)/config:/app/config \ --name crypto-trader \ crypto-trader:latest
Reverse Proxy (Nginx)
Example Nginx configuration:
server {
listen 80;
server_name crypto-trader.example.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws/ {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
Migration from PyQt6
The existing Python code has been preserved:
- Trading engine (
src/trading/) - Strategy framework (
src/strategies/) - Portfolio tracker (
src/portfolio/) - Backtesting engine (
src/backtesting/) - All other core modules
Only the UI layer has been replaced with a web interface.
Troubleshooting
Backend Issues
- Port already in use: Change port in
docker-compose.ymlor use--portflag - Database errors: Check database file permissions in
./datadirectory - Import errors: Ensure
PYTHONPATH=/appis set
Frontend Issues
- API connection errors: Check
VITE_API_URLin.envfile - WebSocket connection fails: Verify WebSocket URL and backend is running
- Build errors: Clear
node_modulesand reinstall:rm -rf node_modules && npm install
Docker Issues
- Build fails: Check Dockerfile syntax and dependencies
- Container won't start: Check logs:
docker-compose logs - Volume permissions: Ensure
./datadirectory is writable
Benefits of Web Architecture
- Modern UI: Access to entire web ecosystem (Material-UI, charts, etc.)
- Cross-platform: Works on any device with a browser
- Easier deployment: Docker is simpler than AppImage
- Better development: Hot-reload, better tooling
- Maintainability: Easier to update and deploy
- Accessibility: Access from anywhere via browser
Next Steps
- Add authentication (JWT tokens)
- Implement WebSocket price updates
- Add more charting capabilities
- Enhance strategy management UI
- Add mobile-responsive design