|
|
@@ -53,8 +53,8 @@ The service includes an MT5 Expert Advisor (EA) that automatically sends histori
|
|
53
|
53
|
- **Validation**: Joi
|
|
54
|
54
|
- **Security**: Helmet, CORS
|
|
55
|
55
|
- **Logging**: Winston, Morgan
|
|
56
|
|
-- **Testing**: Jest
|
|
57
|
|
-- **Development**: Nodemon, ESLint
|
|
|
56
|
+- **Testing**: Jest, Supertest
|
|
|
57
|
+- **Development**: Nodemon, ESLint, Sequelize CLI
|
|
58
|
58
|
|
|
59
|
59
|
## Project Structure
|
|
60
|
60
|
|
|
|
@@ -110,13 +110,13 @@ market-data-service/
|
|
110
|
110
|
```
|
|
111
|
111
|
Edit `.env` with your database credentials and other configuration.
|
|
112
|
112
|
|
|
113
|
|
-4. **Set up the database**
|
|
|
113
|
+4. **Database setup**
|
|
114
|
114
|
```bash
|
|
115
|
115
|
# Create PostgreSQL database
|
|
116
|
116
|
createdb market_data
|
|
117
|
117
|
|
|
118
|
|
- # Run the schema
|
|
119
|
|
- psql -d market_data -f schema.sql
|
|
|
118
|
+ # Run migrations
|
|
|
119
|
+ npx sequelize-cli db:migrate
|
|
120
|
120
|
```
|
|
121
|
121
|
|
|
122
|
122
|
5. **Start the development server**
|
|
|
@@ -182,15 +182,23 @@ CORS_ORIGIN=*
|
|
182
|
182
|
- `POST /api/live-prices/bulk` - Bulk update live prices
|
|
183
|
183
|
- `DELETE /api/live-prices/:symbolId` - Delete live price
|
|
184
|
184
|
|
|
185
|
|
-## Database Schema
|
|
|
185
|
+## Database Management
|
|
186
|
186
|
|
|
187
|
|
-The service uses three main tables:
|
|
|
187
|
+The database schema is managed through Sequelize migrations and models:
|
|
188
|
188
|
|
|
189
|
|
-1. **symbols** - Trading symbols metadata
|
|
190
|
|
-2. **candles_1h** - Hourly OHLCV data
|
|
191
|
|
-3. **live_prices** - Current market prices
|
|
|
189
|
+- Models are defined in `src/models/`
|
|
|
190
|
+- Migrations are stored in `migrations/`
|
|
|
191
|
+- Associations are configured in `src/models/index.js`
|
|
192
|
192
|
|
|
193
|
|
-See `schema.sql` for complete table definitions.
|
|
|
193
|
+Key entities:
|
|
|
194
|
+- **Symbol**: Financial instrument metadata
|
|
|
195
|
+- **Candle1h**: Hourly OHLCV data
|
|
|
196
|
+- **LivePrice**: Real-time market prices
|
|
|
197
|
+
|
|
|
198
|
+To update the database schema:
|
|
|
199
|
+1. Create a new migration: `npx sequelize-cli migration:generate --name description`
|
|
|
200
|
+2. Implement schema changes in the migration file
|
|
|
201
|
+3. Run migrations: `npx sequelize-cli db:migrate`
|
|
194
|
202
|
|
|
195
|
203
|
## Development
|
|
196
|
204
|
|
|
|
@@ -198,8 +206,10 @@ See `schema.sql` for complete table definitions.
|
|
198
|
206
|
|
|
199
|
207
|
- `npm start` - Start production server
|
|
200
|
208
|
- `npm run dev` - Start development server with auto-reload
|
|
201
|
|
-- `npm test` - Run tests
|
|
|
209
|
+- `npm test` - Run Jest test suite
|
|
202
|
210
|
- `npm run test:watch` - Run tests in watch mode
|
|
|
211
|
+- `npm run migrate` - Run database migrations
|
|
|
212
|
+- `npm run migrate:undo` - Revert last migration
|
|
203
|
213
|
- `npm run lint` - Run ESLint
|
|
204
|
214
|
- `npm run lint:fix` - Fix ESLint issues
|
|
205
|
215
|
|
|
|
@@ -209,7 +219,32 @@ This project uses ESLint for code linting. Run `npm run lint` to check for issue
|
|
209
|
219
|
|
|
210
|
220
|
### Testing
|
|
211
|
221
|
|
|
212
|
|
-Tests are written using Jest. Add your test files in the `tests/` directory.
|
|
|
222
|
+The project uses Jest with Supertest for endpoint testing. Key features:
|
|
|
223
|
+
|
|
|
224
|
+- Integration tests with database cleanup
|
|
|
225
|
+- Test environment database configuration
|
|
|
226
|
+- Automatic test isolation with `{ force: true }` sync
|
|
|
227
|
+
|
|
|
228
|
+Run tests:
|
|
|
229
|
+```bash
|
|
|
230
|
+npm test # Run full test suite
|
|
|
231
|
+npm run test:watch # Run in watch mode
|
|
|
232
|
+```
|
|
|
233
|
+
|
|
|
234
|
+### Database Migrations
|
|
|
235
|
+
|
|
|
236
|
+We use Sequelize CLI for database migrations:
|
|
|
237
|
+
|
|
|
238
|
+```bash
|
|
|
239
|
+# Create new migration
|
|
|
240
|
+npx sequelize-cli migration:generate --name your-migration-name
|
|
|
241
|
+
|
|
|
242
|
+# Run pending migrations
|
|
|
243
|
+npx sequelize-cli db:migrate
|
|
|
244
|
+
|
|
|
245
|
+# Revert last migration
|
|
|
246
|
+npx sequelize-cli db:migrate:undo
|
|
|
247
|
+```
|
|
213
|
248
|
|
|
214
|
249
|
## Deployment
|
|
215
|
250
|
|