Some checks failed
Documentation / build-docs (push) Has been cancelled
Tests / test (macos-latest, 3.11) (push) Has been cancelled
Tests / test (macos-latest, 3.12) (push) Has been cancelled
Tests / test (macos-latest, 3.13) (push) Has been cancelled
Tests / test (macos-latest, 3.14) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.14) (push) Has been cancelled
5.8 KiB
5.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)
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
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
Data Persistence
Data is stored in the ~/.local/share/crypto_trader/ directory following XDG Base Directory Specification.
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
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: Use
--portflag to specify a different port - Database errors: Check database connection string and permissions
- Import errors: Ensure virtual environment is activated and dependencies are installed
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
Benefits of Web Architecture
- Modern UI: Access to entire web ecosystem (Material-UI, charts, etc.)
- Cross-platform: Works on any device with a browser
- 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