|
|
@@ -120,20 +120,50 @@ UNIQUE (symbol_id, open_time);
|
|
|
Joi.number().precision(15)
|
|
|
```
|
|
|
|
|
|
-## 🚀 Complete Deployment Guide
|
|
|
+## 🚀 Quick Start
|
|
|
|
|
|
-## 📋 Prerequisites (All Versions)
|
|
|
+### Local Development
|
|
|
|
|
|
-### Required Software (Latest Stable Versions)
|
|
|
-- **Node.js**: v18.x LTS or higher
|
|
|
-- **PostgreSQL**: v13.x or higher
|
|
|
-- **Nginx**: v1.24.x or higher
|
|
|
-- **Git**: Latest version
|
|
|
-- **Certbot** (for SSL certificates)
|
|
|
+```bash
|
|
|
+# Clone repository
|
|
|
+git clone <your-repo-url>
|
|
|
+cd market-data-service
|
|
|
+
|
|
|
+# Start Docker services
|
|
|
+docker-compose up -d
|
|
|
+
|
|
|
+# Access API at http://market-data.local
|
|
|
+```
|
|
|
+
|
|
|
+📖 **For detailed local development setup, see [docs/LOCAL_DEV_SETUP.md](./docs/LOCAL_DEV_SETUP.md)**
|
|
|
+
|
|
|
+### Production Deployment
|
|
|
+
|
|
|
+```bash
|
|
|
+# Set up environment variables
|
|
|
+cp .env.example .env
|
|
|
+# Edit .env with your values
|
|
|
+
|
|
|
+# Start production services
|
|
|
+docker-compose -f docker-compose.prod.yml up -d
|
|
|
+```
|
|
|
+
|
|
|
+📖 **For complete production deployment guide, see [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md)**
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 📚 Documentation
|
|
|
+
|
|
|
+- **[Local Development Setup](./docs/LOCAL_DEV_SETUP.md)** - Complete local development guide
|
|
|
+- **[Production Deployment](./docs/DEPLOYMENT.md)** - Production deployment with SSL certificates
|
|
|
+- **[Docker Guide](./DOCKER.md)** - Docker containerization details
|
|
|
+- **[Configuration Guide](./docs/CONFIGURATION.md)** - Environment variables and configuration
|
|
|
+- **[API Contract](./docs/API_CONTRACT.md)** - API endpoint specifications
|
|
|
+- **[MT5 Operation](./docs/MT5_OPERATION.md)** - MT5 Expert Advisor guide
|
|
|
|
|
|
---
|
|
|
|
|
|
-## 🆕 FRESH SERVER DEPLOYMENT (Step-by-Step)
|
|
|
+## 🆕 FRESH SERVER DEPLOYMENT (Legacy - See DEPLOYMENT.md)
|
|
|
|
|
|
### Step 1: Server Preparation
|
|
|
```bash
|
|
|
@@ -220,6 +250,9 @@ sudo -u postgres psql -d financial_data -c "\dt"
|
|
|
```
|
|
|
|
|
|
### Step 6: Deploy with Docker (Recommended)
|
|
|
+
|
|
|
+> **⚠️ Outdated Instructions:** This section contains legacy deployment steps. For current production deployment with containerized SSL certificates, see **[docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md)**
|
|
|
+
|
|
|
```bash
|
|
|
# Navigate to project directory
|
|
|
cd /root/market-data-service
|
|
|
@@ -232,135 +265,16 @@ nano .env
|
|
|
|
|
|
# Build and start production containers
|
|
|
docker-compose -f docker-compose.prod.yml up -d --build
|
|
|
-
|
|
|
-# Verify containers are running
|
|
|
-docker-compose -f docker-compose.prod.yml ps
|
|
|
-
|
|
|
-# View logs
|
|
|
-docker-compose -f docker-compose.prod.yml logs -f api
|
|
|
```
|
|
|
|
|
|
-For detailed Docker deployment instructions, see [DOCKER.md](./DOCKER.md).
|
|
|
-
|
|
|
-### Step 7: Configure Nginx (WITHOUT SSL first)
|
|
|
-```bash
|
|
|
-# Copy nginx configuration
|
|
|
-sudo cp nginx-1.24.0/conf/nginx.conf /etc/nginx/nginx.conf
|
|
|
-
|
|
|
-# Test configuration
|
|
|
-sudo nginx -t
|
|
|
-
|
|
|
-# Start Nginx
|
|
|
-sudo systemctl enable nginx
|
|
|
-sudo systemctl start nginx
|
|
|
-```
|
|
|
-
|
|
|
-### Step 8: Install SSL Certificate (Certbot)
|
|
|
-```bash
|
|
|
-# Install certbot
|
|
|
-sudo apt install -y certbot python3-certbot-nginx
|
|
|
-
|
|
|
-# Generate SSL certificate
|
|
|
-sudo certbot --nginx -d your-domain.com
|
|
|
-
|
|
|
-# Test certificate
|
|
|
-sudo certbot certificates
|
|
|
-```
|
|
|
-
|
|
|
-### Step 9: Update Nginx for SSL (After Certificate Generation)
|
|
|
-```bash
|
|
|
-# Update nginx configuration with SSL
|
|
|
-sudo tee /etc/nginx/sites-available/market-data-api << EOF
|
|
|
-server {
|
|
|
- listen 80;
|
|
|
- server_name your-domain.com;
|
|
|
-
|
|
|
- # Redirect HTTP to HTTPS
|
|
|
- return 301 https://\$server_name\$request_uri;
|
|
|
-}
|
|
|
-
|
|
|
-server {
|
|
|
- listen 443 ssl http2;
|
|
|
- server_name your-domain.com;
|
|
|
-
|
|
|
- # SSL Configuration
|
|
|
- ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
|
|
|
- ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
|
|
|
- ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
- ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
|
|
|
- ssl_prefer_server_ciphers off;
|
|
|
-
|
|
|
- # Security Headers
|
|
|
- add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
- add_header X-Frame-Options DENY always;
|
|
|
- add_header X-Content-Type-Options nosniff always;
|
|
|
- add_header X-XSS-Protection "1; mode=block" always;
|
|
|
-
|
|
|
- # API Proxy Settings
|
|
|
- location /api/ {
|
|
|
- proxy_pass http://localhost:3001;
|
|
|
- proxy_http_version 1.1;
|
|
|
- proxy_set_header Upgrade \$http_upgrade;
|
|
|
- proxy_set_header Connection 'upgrade';
|
|
|
- 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;
|
|
|
-
|
|
|
- # Timeout and buffer settings
|
|
|
- proxy_connect_timeout 60s;
|
|
|
- proxy_send_timeout 60s;
|
|
|
- proxy_read_timeout 60s;
|
|
|
- proxy_buffering on;
|
|
|
- proxy_buffer_size 4k;
|
|
|
- proxy_buffers 8 4k;
|
|
|
- client_max_body_size 50M;
|
|
|
- }
|
|
|
-
|
|
|
- location /health {
|
|
|
- proxy_pass http://localhost:3001/health;
|
|
|
- proxy_http_version 1.1;
|
|
|
- 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 / {
|
|
|
- return 200 "Market Data API is running. Use /api/ for endpoints\\n";
|
|
|
- add_header Content-Type text/plain;
|
|
|
- }
|
|
|
-}
|
|
|
-EOF
|
|
|
-
|
|
|
-# Enable site and restart nginx
|
|
|
-sudo ln -s /etc/nginx/sites-available/market-data-api /etc/nginx/sites-enabled/
|
|
|
-sudo rm -f /etc/nginx/sites-enabled/default
|
|
|
-sudo nginx -t
|
|
|
-sudo systemctl restart nginx
|
|
|
-```
|
|
|
-
|
|
|
-### Step 10: Final Testing
|
|
|
-```bash
|
|
|
-# Test HTTP to HTTPS redirect
|
|
|
-curl -I http://your-domain.com
|
|
|
-
|
|
|
-# Test HTTPS API endpoints
|
|
|
-curl https://your-domain.com/health
|
|
|
-curl https://your-domain.com/api/health
|
|
|
-curl https://your-domain.com/api/symbols
|
|
|
-
|
|
|
-# Test bulk endpoint
|
|
|
-curl -X POST https://your-domain.com/api/live-prices/bulk \
|
|
|
- -H "Content-Type: application/json" \
|
|
|
- -d '{"prices": [{"symbolId": 1, "price": 123.45}]}'
|
|
|
-```
|
|
|
+📖 **For detailed Docker deployment instructions, see [DOCKER.md](./DOCKER.md)**
|
|
|
+📖 **For production deployment with SSL, see [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md)**
|
|
|
|
|
|
---
|
|
|
|
|
|
-## 💻 LOCAL DEVELOPMENT SETUP
|
|
|
+## 💻 Local Development
|
|
|
|
|
|
-This section provides a quick overview. For detailed instructions, troubleshooting, and advanced configuration, see **[docs/LOCAL_DEV_SETUP.md](./docs/LOCAL_DEV_SETUP.md)**.
|
|
|
+> **Quick Overview:** For complete setup instructions, troubleshooting, and MT5 EA configuration, see **[docs/LOCAL_DEV_SETUP.md](./docs/LOCAL_DEV_SETUP.md)**.
|
|
|
|
|
|
### Prerequisites
|
|
|
- **Docker** and **Docker Compose** installed
|
|
|
@@ -633,14 +547,8 @@ sudo tail -f /var/log/nginx/error.log
|
|
|
```
|
|
|
|
|
|
### SSL Certificate Auto-Renewal
|
|
|
-```bash
|
|
|
-# Check renewal status
|
|
|
-sudo certbot certificates
|
|
|
-sudo systemctl status certbot.timer
|
|
|
|
|
|
-# Manual renewal test
|
|
|
-sudo certbot renew --dry-run
|
|
|
-```
|
|
|
+> **Note:** SSL certificates are now automatically managed via Docker containers. See [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md) for details.
|
|
|
|
|
|
---
|
|
|
|
|
|
@@ -698,60 +606,26 @@ psql financial_data < backup.sql
|
|
|
|
|
|
## Environment Variables
|
|
|
|
|
|
-Create a `.env` file in the root directory with the following variables:
|
|
|
-
|
|
|
-```env
|
|
|
-# Database Configuration
|
|
|
-DB_HOST=localhost
|
|
|
-DB_PORT=5432
|
|
|
-DB_NAME=market_data
|
|
|
-DB_USER=your_username
|
|
|
-DB_PASSWORD=your_password
|
|
|
-
|
|
|
-# Server Configuration
|
|
|
-PORT=3001
|
|
|
-NODE_ENV=development
|
|
|
-
|
|
|
-# JWT Configuration (if needed for authentication)
|
|
|
-JWT_SECRET=your_jwt_secret_key
|
|
|
-
|
|
|
-# API Keys (if needed for external services)
|
|
|
-# BINANCE_API_KEY=your_api_key
|
|
|
-# BINANCE_API_SECRET=your_api_secret
|
|
|
+See **[docs/CONFIGURATION.md](./docs/CONFIGURATION.md)** for complete environment variable documentation.
|
|
|
|
|
|
-# CORS Configuration
|
|
|
-CORS_ORIGIN=*
|
|
|
-```
|
|
|
+**Quick Reference:**
|
|
|
+- `DB_PASSWORD` - Database password (required)
|
|
|
+- `JWT_SECRET` - JWT secret key (required)
|
|
|
+- `DOMAIN_NAME` - Domain for SSL certificates (production)
|
|
|
+- `SSL_EMAIL` - Email for Let's Encrypt (production)
|
|
|
+- `CORS_ORIGIN` - Allowed CORS origins
|
|
|
|
|
|
## API Endpoints
|
|
|
|
|
|
-### Health Check
|
|
|
-- `GET /health` - Check service health
|
|
|
-
|
|
|
-### Symbols
|
|
|
-- `GET /api/symbols` - Get all symbols (with filtering)
|
|
|
-- `GET /api/symbols/search?q=EURUSD` - Search symbols by name
|
|
|
-- `GET /api/symbols/:id` - Get symbol by ID
|
|
|
-- `POST /api/symbols` - Create new symbol
|
|
|
-- `PUT /api/symbols/:id` - Update symbol
|
|
|
-- `DELETE /api/symbols/:id` - Delete symbol (soft delete)
|
|
|
-
|
|
|
-### Candles
|
|
|
-- `GET /api/candles?symbolId=1&startTime=2025-01-01T00:00:00Z&endTime=2025-01-02T00:00:00Z&limit=100&offset=0` - Get candles with filtering
|
|
|
-- `GET /api/candles/ohlc?symbolId=1&period=1h&limit=100` - Get OHLC data
|
|
|
-- `GET /api/candles/:symbolId/latest` - Get latest candle for symbol
|
|
|
-- `POST /api/candles` - Create new candle
|
|
|
+See **[docs/API_CONTRACT.md](./docs/API_CONTRACT.md)** for complete API documentation.
|
|
|
+
|
|
|
+**Quick Reference:**
|
|
|
+- `GET /health` - Health check
|
|
|
+- `GET /api/symbols` - Get all symbols
|
|
|
+- `GET /api/candles` - Get candle data
|
|
|
- `POST /api/candles/bulk` - Bulk create candles
|
|
|
-- `DELETE /api/candles/cleanup/:symbolId?keep=1000` - Clean up old candles, keep latest N (default 1000)
|
|
|
-
|
|
|
-### Live Prices
|
|
|
-- `GET /api/live-prices` - Get all live prices
|
|
|
-- `GET /api/live-prices/exchange/:exchange` - Get live prices by exchange
|
|
|
-- `GET /api/live-prices/type/:type` - Get live prices by instrument type
|
|
|
-- `GET /api/live-prices/:symbolId` - Get live price for symbol
|
|
|
-- `POST /api/live-prices` - Create/update live price
|
|
|
+- `GET /api/live-prices` - Get live prices
|
|
|
- `POST /api/live-prices/bulk` - Bulk update live prices
|
|
|
-- `DELETE /api/live-prices/:symbolId` - Delete live price
|
|
|
|
|
|
## Development
|
|
|
|
|
|
@@ -784,9 +658,8 @@ npx sequelize-cli db:migrate:undo
|
|
|
|
|
|
## Deployment
|
|
|
|
|
|
-The project is fully containerized using Docker. For deployment:
|
|
|
-
|
|
|
-1. **Development**: Use `docker-compose up -d`
|
|
|
-2. **Production**: Use `docker-compose -f docker-compose.prod.yml up -d`
|
|
|
+The project is fully containerized using Docker with automatic SSL certificate management.
|
|
|
|
|
|
-See [DOCKER.md](./DOCKER.md) for complete deployment instructions.
|
|
|
+- **Development**: See [docs/LOCAL_DEV_SETUP.md](./docs/LOCAL_DEV_SETUP.md)
|
|
|
+- **Production**: See [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md)
|
|
|
+- **Docker Details**: See [DOCKER.md](./DOCKER.md)
|