|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+# Local Development Setup Guide
|
|
|
2
|
+
|
|
|
3
|
+This guide will help you set up the Market Data Service for local development with MT5 EA connectivity.
|
|
|
4
|
+
|
|
|
5
|
+## Quick Start (5 minutes)
|
|
|
6
|
+
|
|
|
7
|
+### Prerequisites
|
|
|
8
|
+- Docker and Docker Compose installed
|
|
|
9
|
+- Git installed
|
|
|
10
|
+- Administrator access (script will prompt for password automatically on macOS)
|
|
|
11
|
+
|
|
|
12
|
+### Step 1: Clone and Setup Hosts File
|
|
|
13
|
+
|
|
|
14
|
+```bash
|
|
|
15
|
+# Clone the repository
|
|
|
16
|
+git clone https://git.mqldevelopment.com/muhammad.uzair/market-data-service.git
|
|
|
17
|
+cd market-data-service
|
|
|
18
|
+
|
|
|
19
|
+# Run the automated setup script (fully automated - will prompt for password on macOS)
|
|
|
20
|
+# On Linux, you may need: sudo bash scripts/setup-local-dev.sh
|
|
|
21
|
+bash scripts/setup-local-dev.sh
|
|
|
22
|
+```
|
|
|
23
|
+
|
|
|
24
|
+**Note:** On macOS, the script automatically prompts for your administrator password using a system dialog. On Linux, you may need to run with `sudo`.
|
|
|
25
|
+
|
|
|
26
|
+**Alternative (Manual Setup):**
|
|
|
27
|
+If you prefer to do it manually:
|
|
|
28
|
+```bash
|
|
|
29
|
+# Add market-data.local to your hosts file
|
|
|
30
|
+echo "127.0.0.1 market-data.local" | sudo tee -a /etc/hosts
|
|
|
31
|
+```
|
|
|
32
|
+
|
|
|
33
|
+### Step 2: Start Docker Services
|
|
|
34
|
+
|
|
|
35
|
+```bash
|
|
|
36
|
+# Start all services (database, API, Nginx)
|
|
|
37
|
+docker-compose up -d
|
|
|
38
|
+
|
|
|
39
|
+# Verify services are running
|
|
|
40
|
+docker-compose ps
|
|
|
41
|
+```
|
|
|
42
|
+
|
|
|
43
|
+### Step 3: Verify Setup
|
|
|
44
|
+
|
|
|
45
|
+```bash
|
|
|
46
|
+# Test health endpoint
|
|
|
47
|
+curl http://market-data.local/health
|
|
|
48
|
+
|
|
|
49
|
+# Test API endpoint
|
|
|
50
|
+curl http://market-data.local/api/symbols
|
|
|
51
|
+```
|
|
|
52
|
+
|
|
|
53
|
+You should see JSON responses. If you do, your setup is complete! ✅
|
|
|
54
|
+
|
|
|
55
|
+---
|
|
|
56
|
+
|
|
|
57
|
+## Why market-data.local?
|
|
|
58
|
+
|
|
|
59
|
+MT5 Expert Advisors require valid domain URLs in their "Allowed URLs" list. MT5 **does not allow**:
|
|
|
60
|
+- ❌ `localhost`
|
|
|
61
|
+- ❌ `127.0.0.1`
|
|
|
62
|
+- ❌ `http://localhost:80`
|
|
|
63
|
+
|
|
|
64
|
+MT5 **requires** a domain-like URL:
|
|
|
65
|
+- ✅ `http://market-data.local`
|
|
|
66
|
+
|
|
|
67
|
+The `market-data.local` domain resolves to your local Docker setup via the `/etc/hosts` file, allowing MT5 EA to connect to your local development server.
|
|
|
68
|
+
|
|
|
69
|
+---
|
|
|
70
|
+
|
|
|
71
|
+## Complete Setup Instructions
|
|
|
72
|
+
|
|
|
73
|
+### 1. Hosts File Configuration
|
|
|
74
|
+
|
|
|
75
|
+The setup script (`bash scripts/setup-local-dev.sh`) automatically adds the required entry. On macOS, it will prompt for your administrator password using a system dialog. On Linux, you may need to run it with `sudo`.
|
|
|
76
|
+
|
|
|
77
|
+**Verify the entry:**
|
|
|
78
|
+```bash
|
|
|
79
|
+# View current entry
|
|
|
80
|
+cat /etc/hosts | grep market-data.local
|
|
|
81
|
+```
|
|
|
82
|
+
|
|
|
83
|
+**Manual setup (if needed):**
|
|
|
84
|
+```bash
|
|
|
85
|
+# Add entry manually (macOS/Linux)
|
|
|
86
|
+echo "127.0.0.1 market-data.local" | sudo tee -a /etc/hosts
|
|
|
87
|
+```
|
|
|
88
|
+
|
|
|
89
|
+**Windows:**
|
|
|
90
|
+1. Open Notepad as Administrator
|
|
|
91
|
+2. Open `C:\Windows\System32\drivers\etc\hosts`
|
|
|
92
|
+3. Add line: `127.0.0.1 market-data.local`
|
|
|
93
|
+4. Save and close
|
|
|
94
|
+
|
|
|
95
|
+### 2. Docker Services
|
|
|
96
|
+
|
|
|
97
|
+**Start Services:**
|
|
|
98
|
+```bash
|
|
|
99
|
+docker-compose up -d
|
|
|
100
|
+```
|
|
|
101
|
+
|
|
|
102
|
+**View Logs:**
|
|
|
103
|
+```bash
|
|
|
104
|
+# All services
|
|
|
105
|
+docker-compose logs -f
|
|
|
106
|
+
|
|
|
107
|
+# Specific service
|
|
|
108
|
+docker-compose logs -f api
|
|
|
109
|
+docker-compose logs -f nginx
|
|
|
110
|
+docker-compose logs -f db
|
|
|
111
|
+```
|
|
|
112
|
+
|
|
|
113
|
+**Stop Services:**
|
|
|
114
|
+```bash
|
|
|
115
|
+docker-compose down
|
|
|
116
|
+```
|
|
|
117
|
+
|
|
|
118
|
+**Restart Services:**
|
|
|
119
|
+```bash
|
|
|
120
|
+docker-compose restart
|
|
|
121
|
+```
|
|
|
122
|
+
|
|
|
123
|
+### 3. Verify Services
|
|
|
124
|
+
|
|
|
125
|
+**Check Service Status:**
|
|
|
126
|
+```bash
|
|
|
127
|
+docker-compose ps
|
|
|
128
|
+```
|
|
|
129
|
+
|
|
|
130
|
+All services should show "Up" status.
|
|
|
131
|
+
|
|
|
132
|
+**Test Endpoints:**
|
|
|
133
|
+```bash
|
|
|
134
|
+# Health check
|
|
|
135
|
+curl http://market-data.local/health
|
|
|
136
|
+
|
|
|
137
|
+# API endpoints
|
|
|
138
|
+curl http://market-data.local/api/symbols
|
|
|
139
|
+curl http://market-data.local/api/health
|
|
|
140
|
+
|
|
|
141
|
+# Test with browser
|
|
|
142
|
+open http://market-data.local/health # macOS
|
|
|
143
|
+# or visit http://market-data.local/health in your browser
|
|
|
144
|
+```
|
|
|
145
|
+
|
|
|
146
|
+---
|
|
|
147
|
+
|
|
|
148
|
+## MT5 EA Configuration
|
|
|
149
|
+
|
|
|
150
|
+### Step 1: Add URL to MT5 Allowed List
|
|
|
151
|
+
|
|
|
152
|
+1. Open MT5
|
|
|
153
|
+2. Go to: **Tools → Options → Expert Advisors**
|
|
|
154
|
+3. Click the **"Allowed URLs"** tab
|
|
|
155
|
+4. Click **"Add"**
|
|
|
156
|
+5. Enter: `http://market-data.local`
|
|
|
157
|
+6. Click **"OK"**
|
|
|
158
|
+
|
|
|
159
|
+### Step 2: Configure EA
|
|
|
160
|
+
|
|
|
161
|
+1. Attach `MarketDataSender.mq5` to any chart
|
|
|
162
|
+2. In EA Inputs, set:
|
|
|
163
|
+ - **ApiBaseUrl**: `http://market-data.local`
|
|
|
164
|
+ - **HistoricalCandleCount**: `1000` (or your preference)
|
|
|
165
|
+ - **LivePriceIntervalSeconds**: `5` (or your preference)
|
|
|
166
|
+3. Click **"OK"**
|
|
|
167
|
+
|
|
|
168
|
+### Step 3: Verify Connection
|
|
|
169
|
+
|
|
|
170
|
+1. Check the **Experts** tab in MT5 Terminal
|
|
|
171
|
+2. Look for EA logs:
|
|
|
172
|
+ - ✅ `✅ Symbols initialized: X`
|
|
|
173
|
+ - ✅ `✅ Successfully sent live prices to API`
|
|
|
174
|
+ - ❌ If you see errors, check troubleshooting section below
|
|
|
175
|
+
|
|
|
176
|
+---
|
|
|
177
|
+
|
|
|
178
|
+## Testing the Setup
|
|
|
179
|
+
|
|
|
180
|
+### Test 1: Basic Connectivity
|
|
|
181
|
+
|
|
|
182
|
+```bash
|
|
|
183
|
+# Health check
|
|
|
184
|
+curl http://market-data.local/health
|
|
|
185
|
+
|
|
|
186
|
+# Expected response:
|
|
|
187
|
+# {"success":true,"message":"Market Data Service is running",...}
|
|
|
188
|
+```
|
|
|
189
|
+
|
|
|
190
|
+### Test 2: API Endpoints
|
|
|
191
|
+
|
|
|
192
|
+```bash
|
|
|
193
|
+# Get symbols
|
|
|
194
|
+curl http://market-data.local/api/symbols
|
|
|
195
|
+
|
|
|
196
|
+# Get health
|
|
|
197
|
+curl http://market-data.local/api/health
|
|
|
198
|
+```
|
|
|
199
|
+
|
|
|
200
|
+### Test 3: MT5 EA Connection
|
|
|
201
|
+
|
|
|
202
|
+1. Start MT5 EA with `ApiBaseUrl = "http://market-data.local"`
|
|
|
203
|
+2. Check MT5 Experts tab for logs
|
|
|
204
|
+3. Verify symbols are being synced
|
|
|
205
|
+4. Check that live prices are being sent
|
|
|
206
|
+
|
|
|
207
|
+### Test 4: Database Verification
|
|
|
208
|
+
|
|
|
209
|
+```bash
|
|
|
210
|
+# Connect to database
|
|
|
211
|
+docker-compose exec db psql -U postgres -d financial_data
|
|
|
212
|
+
|
|
|
213
|
+# Check tables
|
|
|
214
|
+\dt
|
|
|
215
|
+
|
|
|
216
|
+# Check symbols
|
|
|
217
|
+SELECT * FROM symbols LIMIT 5;
|
|
|
218
|
+
|
|
|
219
|
+# Check live prices
|
|
|
220
|
+SELECT * FROM live_prices LIMIT 5;
|
|
|
221
|
+
|
|
|
222
|
+# Exit
|
|
|
223
|
+\q
|
|
|
224
|
+```
|
|
|
225
|
+
|
|
|
226
|
+---
|
|
|
227
|
+
|
|
|
228
|
+## Troubleshooting
|
|
|
229
|
+
|
|
|
230
|
+### Issue: "curl: Could not resolve host: market-data.local"
|
|
|
231
|
+
|
|
|
232
|
+**Solution:**
|
|
|
233
|
+```bash
|
|
|
234
|
+# Verify hosts entry exists
|
|
|
235
|
+cat /etc/hosts | grep market-data.local
|
|
|
236
|
+
|
|
|
237
|
+# If missing, add it
|
|
|
238
|
+echo "127.0.0.1 market-data.local" | sudo tee -a /etc/hosts
|
|
|
239
|
+
|
|
|
240
|
+# Flush DNS cache (macOS)
|
|
|
241
|
+sudo dscacheutil -flushcache
|
|
|
242
|
+
|
|
|
243
|
+# Flush DNS cache (Linux)
|
|
|
244
|
+sudo systemd-resolve --flush-caches
|
|
|
245
|
+```
|
|
|
246
|
+
|
|
|
247
|
+### Issue: "502 Bad Gateway" or "Connection refused"
|
|
|
248
|
+
|
|
|
249
|
+**Solution:**
|
|
|
250
|
+```bash
|
|
|
251
|
+# Check if services are running
|
|
|
252
|
+docker-compose ps
|
|
|
253
|
+
|
|
|
254
|
+# If not running, start them
|
|
|
255
|
+docker-compose up -d
|
|
|
256
|
+
|
|
|
257
|
+# Check service logs
|
|
|
258
|
+docker-compose logs api
|
|
|
259
|
+docker-compose logs nginx
|
|
|
260
|
+
|
|
|
261
|
+# Restart services
|
|
|
262
|
+docker-compose restart
|
|
|
263
|
+```
|
|
|
264
|
+
|
|
|
265
|
+### Issue: MT5 EA shows "WebRequest connection error"
|
|
|
266
|
+
|
|
|
267
|
+**Solution:**
|
|
|
268
|
+1. Verify URL is in MT5 Allowed URLs list
|
|
|
269
|
+2. Check URL format: `http://market-data.local` (no trailing slash)
|
|
|
270
|
+3. Test URL manually: `curl http://market-data.local/health`
|
|
|
271
|
+4. Verify Docker services are running: `docker-compose ps`
|
|
|
272
|
+5. Check Nginx logs: `docker-compose logs nginx`
|
|
|
273
|
+
|
|
|
274
|
+### Issue: "Failed to fetch symbols from API: HTTP 502"
|
|
|
275
|
+
|
|
|
276
|
+**Solution:**
|
|
|
277
|
+```bash
|
|
|
278
|
+# Check API service
|
|
|
279
|
+docker-compose logs api
|
|
|
280
|
+
|
|
|
281
|
+# Check database connection
|
|
|
282
|
+docker-compose exec db pg_isready -U postgres
|
|
|
283
|
+
|
|
|
284
|
+# Restart API service
|
|
|
285
|
+docker-compose restart api
|
|
|
286
|
+```
|
|
|
287
|
+
|
|
|
288
|
+### Issue: Database connection errors
|
|
|
289
|
+
|
|
|
290
|
+**Solution:**
|
|
|
291
|
+```bash
|
|
|
292
|
+# Check database is running
|
|
|
293
|
+docker-compose ps db
|
|
|
294
|
+
|
|
|
295
|
+# Check database logs
|
|
|
296
|
+docker-compose logs db
|
|
|
297
|
+
|
|
|
298
|
+# Restart database
|
|
|
299
|
+docker-compose restart db
|
|
|
300
|
+
|
|
|
301
|
+# Wait for database to be ready
|
|
|
302
|
+docker-compose exec db pg_isready -U postgres
|
|
|
303
|
+```
|
|
|
304
|
+
|
|
|
305
|
+### Issue: Port 80 already in use
|
|
|
306
|
+
|
|
|
307
|
+**Solution:**
|
|
|
308
|
+```bash
|
|
|
309
|
+# Check what's using port 80
|
|
|
310
|
+sudo lsof -i :80
|
|
|
311
|
+
|
|
|
312
|
+# Stop conflicting service or change Nginx port in docker-compose.yml
|
|
|
313
|
+# Edit docker-compose.yml, change "80:80" to "8080:80"
|
|
|
314
|
+# Then use: http://market-data.local:8080
|
|
|
315
|
+```
|
|
|
316
|
+
|
|
|
317
|
+---
|
|
|
318
|
+
|
|
|
319
|
+## Development Workflow
|
|
|
320
|
+
|
|
|
321
|
+### Making Code Changes
|
|
|
322
|
+
|
|
|
323
|
+The API service uses volume mounts for live code reloading:
|
|
|
324
|
+
|
|
|
325
|
+```bash
|
|
|
326
|
+# Code changes in src/ are automatically reloaded
|
|
|
327
|
+# No need to restart containers
|
|
|
328
|
+
|
|
|
329
|
+# View API logs to see changes
|
|
|
330
|
+docker-compose logs -f api
|
|
|
331
|
+```
|
|
|
332
|
+
|
|
|
333
|
+### Database Migrations
|
|
|
334
|
+
|
|
|
335
|
+Migrations run automatically on container start. To run manually:
|
|
|
336
|
+
|
|
|
337
|
+```bash
|
|
|
338
|
+# Run migrations
|
|
|
339
|
+docker-compose exec api npx sequelize-cli db:migrate
|
|
|
340
|
+
|
|
|
341
|
+# Check migration status
|
|
|
342
|
+docker-compose exec api npx sequelize-cli db:migrate:status
|
|
|
343
|
+```
|
|
|
344
|
+
|
|
|
345
|
+### Viewing Logs
|
|
|
346
|
+
|
|
|
347
|
+```bash
|
|
|
348
|
+# All services
|
|
|
349
|
+docker-compose logs -f
|
|
|
350
|
+
|
|
|
351
|
+# Specific service
|
|
|
352
|
+docker-compose logs -f api
|
|
|
353
|
+docker-compose logs -f nginx
|
|
|
354
|
+docker-compose logs -f db
|
|
|
355
|
+
|
|
|
356
|
+# Last 100 lines
|
|
|
357
|
+docker-compose logs --tail=100 api
|
|
|
358
|
+```
|
|
|
359
|
+
|
|
|
360
|
+---
|
|
|
361
|
+
|
|
|
362
|
+## Switching Between Local and Production
|
|
|
363
|
+
|
|
|
364
|
+### Local Development
|
|
|
365
|
+- **URL**: `http://market-data.local`
|
|
|
366
|
+- **MT5 EA**: `ApiBaseUrl = "http://market-data.local"`
|
|
|
367
|
+
|
|
|
368
|
+### Production
|
|
|
369
|
+- **URL**: `http://market-price.insightbull.io`
|
|
|
370
|
+- **MT5 EA**: `ApiBaseUrl = "http://market-price.insightbull.io"`
|
|
|
371
|
+
|
|
|
372
|
+You can easily switch by changing the `ApiBaseUrl` input in MT5 EA settings.
|
|
|
373
|
+
|
|
|
374
|
+---
|
|
|
375
|
+
|
|
|
376
|
+## Cleanup
|
|
|
377
|
+
|
|
|
378
|
+### Remove Hosts Entry (if needed)
|
|
|
379
|
+
|
|
|
380
|
+**macOS/Linux:**
|
|
|
381
|
+```bash
|
|
|
382
|
+# Remove the entry
|
|
|
383
|
+sudo sed -i '' '/market-data.local/d' /etc/hosts # macOS
|
|
|
384
|
+sudo sed -i '/market-data.local/d' /etc/hosts # Linux
|
|
|
385
|
+```
|
|
|
386
|
+
|
|
|
387
|
+**Windows:**
|
|
|
388
|
+1. Open Notepad as Administrator
|
|
|
389
|
+2. Open `C:\Windows\System32\drivers\etc\hosts`
|
|
|
390
|
+3. Remove line: `127.0.0.1 market-data.local`
|
|
|
391
|
+4. Save and close
|
|
|
392
|
+
|
|
|
393
|
+### Stop Docker Services
|
|
|
394
|
+
|
|
|
395
|
+```bash
|
|
|
396
|
+# Stop and remove containers
|
|
|
397
|
+docker-compose down
|
|
|
398
|
+
|
|
|
399
|
+# Stop and remove containers + volumes (⚠️ deletes database data)
|
|
|
400
|
+docker-compose down -v
|
|
|
401
|
+```
|
|
|
402
|
+
|
|
|
403
|
+---
|
|
|
404
|
+
|
|
|
405
|
+## Additional Resources
|
|
|
406
|
+
|
|
|
407
|
+- **Main README**: See [README.md](../README.md) for general project information
|
|
|
408
|
+- **Docker Guide**: See [DOCKER.md](../DOCKER.md) for Docker-specific details
|
|
|
409
|
+- **API Documentation**: See [docs/API_CONTRACT.md](./API_CONTRACT.md)
|
|
|
410
|
+- **MT5 Operation**: See [docs/MT5_OPERATION.md](./MT5_OPERATION.md)
|
|
|
411
|
+
|
|
|
412
|
+---
|
|
|
413
|
+
|
|
|
414
|
+## Quick Reference
|
|
|
415
|
+
|
|
|
416
|
+### Essential Commands
|
|
|
417
|
+
|
|
|
418
|
+```bash
|
|
|
419
|
+# Setup (one-time, fully automated on macOS)
|
|
|
420
|
+bash scripts/setup-local-dev.sh
|
|
|
421
|
+# On Linux, you may need: sudo bash scripts/setup-local-dev.sh
|
|
|
422
|
+
|
|
|
423
|
+# Start services
|
|
|
424
|
+docker-compose up -d
|
|
|
425
|
+
|
|
|
426
|
+# Stop services
|
|
|
427
|
+docker-compose down
|
|
|
428
|
+
|
|
|
429
|
+# View logs
|
|
|
430
|
+docker-compose logs -f api
|
|
|
431
|
+
|
|
|
432
|
+# Test endpoint
|
|
|
433
|
+curl http://market-data.local/health
|
|
|
434
|
+
|
|
|
435
|
+# Check services
|
|
|
436
|
+docker-compose ps
|
|
|
437
|
+```
|
|
|
438
|
+
|
|
|
439
|
+### URLs
|
|
|
440
|
+
|
|
|
441
|
+- **Local API**: `http://market-data.local`
|
|
|
442
|
+- **Health Check**: `http://market-data.local/health`
|
|
|
443
|
+- **API Endpoints**: `http://market-data.local/api/*`
|
|
|
444
|
+
|
|
|
445
|
+### MT5 Configuration
|
|
|
446
|
+
|
|
|
447
|
+- **Allowed URL**: `http://market-data.local`
|
|
|
448
|
+- **EA ApiBaseUrl**: `http://market-data.local`
|
|
|
449
|
+
|
|
|
450
|
+---
|
|
|
451
|
+
|
|
|
452
|
+## Need Help?
|
|
|
453
|
+
|
|
|
454
|
+If you encounter issues not covered in this guide:
|
|
|
455
|
+
|
|
|
456
|
+1. Check the troubleshooting section above
|
|
|
457
|
+2. Review service logs: `docker-compose logs`
|
|
|
458
|
+3. Verify hosts entry: `cat /etc/hosts | grep market-data.local`
|
|
|
459
|
+4. Test connectivity: `curl http://market-data.local/health`
|
|
|
460
|
+
|
|
|
461
|
+For additional support, check the main [README.md](../README.md) or project documentation.
|
|
|
462
|
+
|