Market Data Service is a high-performance financial data API that provides comprehensive Symbol prices of different markets through both RESTful endpoints and real-time WebSocket connections.
|
|
3 月之前 | |
|---|---|---|
| MT5 | 3 月之前 | |
| config | 3 月之前 | |
| docs | 4 月之前 | |
| migrations | 4 月之前 | |
| models | 4 月之前 | |
| src | 3 月之前 | |
| tests | 3 月之前 | |
| .gitignore | 4 月之前 | |
| README.md | 3 月之前 | |
| package-lock.json | 4 月之前 | |
| package.json | 4 月之前 | |
| schema.sql | 4 月之前 |
A high-performance financial data API that provides comprehensive market data for various financial instruments including cryptocurrencies, stocks, forex, and commodities through both RESTful endpoints and real-time WebSocket connections.
The service includes an MT5 Expert Advisor (EA) that automatically sends historical candle data and live tick prices to the API.
MT5/Experts/MarketDataSender.mq5 to your MT5 Experts directoryConfigure EA settings:
ApiBaseUrl: Your API endpoint (e.g., http://your-server:3000)ApiKey: Optional authentication keyHistoricalCandleCount: Number of historical candles to send (default: 1000)HistoricalTimeframe: Timeframe for historical data (default: H1)Attach the EA to any MT5 chart
The EA will:
EXCHANGE_SYMBOL)✅ MT5 Integration
✅ Data Integrity
✅ Reliability
Comprehensive test coverage
Multi-Asset Support: Handles cryptocurrencies, stocks, forex, and commodities
Real-time Data: Live price feeds with bid/ask spreads
Historical Data: OHLCV candle data with flexible timeframes
RESTful API: Well-structured endpoints for all operations
Data Validation: Comprehensive input validation using Joi
Error Handling: Robust error handling with detailed responses
Security: Helmet.js for security headers, CORS support
Logging: Winston-based logging with multiple transports
Database: PostgreSQL with Sequelize ORM
Scalable Architecture: Modular design with controllers, routes, and middleware
market-data-service/
├── src/
│ ├── config/
│ │ └── database.js # Database configuration
│ ├── controllers/
│ │ ├── symbolController.js # Symbol CRUD operations
│ │ ├── candleController.js # Candle data operations
│ │ └── livePriceController.js # Live price operations
│ ├── middleware/
│ │ ├── errorHandler.js # Global error handling
│ │ └── validation.js # Request validation
│ ├── models/
│ │ ├── Symbol.js # Symbol model
│ │ ├── Candle1h.js # 1-hour candle model
│ │ ├── LivePrice.js # Live price model
│ │ └── index.js # Model associations
│ ├── routes/
│ │ ├── symbols.js # Symbol routes
│ │ ├── candles.js # Candle routes
│ │ └── livePrices.js # Live price routes
│ ├── utils/
│ │ └── logger.js # Logging utility
│ ├── app.js # Express app configuration
│ └── server.js # Server startup
├── tests/ # Test files
├── schema.sql # Database schema
├── .env # Environment variables
├── .gitignore # Git ignore rules
├── package.json # Dependencies and scripts
└── README.md # This file
Database Constraints
ALTER TABLE candles_1h
ADD CONSTRAINT unique_symbol_open_time
UNIQUE (symbol_id, open_time);
Precision Requirements
// All numeric fields require 15 decimal precision
Joi.number().precision(15)
Clone the repository
git clone https://git.mqldevelopment.com/muhammad.uzair/market-data-service.git
cd market-data-service
Install dependencies
npm install
Set up environment variables
cp .env.example .env
Edit .env with your database credentials and other configuration.
Database setup ```bash
createdb market_data
# Run migrations npx sequelize-cli db:migrate
5. **Start the development server**
```bash
npm run dev
The server will start on http://localhost:3000
Create a .env file in the root directory with the following variables:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=market_data
DB_USER=your_username
DB_PASSWORD=your_password
# Server Configuration
PORT=3000
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
# CORS Configuration
CORS_ORIGIN=*
GET /health - Check service healthGET /api/symbols - Get all symbols (with filtering)GET /api/symbols/search - Search symbols by nameGET /api/symbols/:id - Get symbol by IDPOST /api/symbols - Create new symbolPUT /api/symbols/:id - Update symbolDELETE /api/symbols/:id - Delete symbol (soft delete)GET /api/candles - Get candles with filteringGET /api/candles/ohlc - Get OHLC dataGET /api/candles/:symbolId/latest - Get latest candle for symbolPOST /api/candles - Create new candlePOST /api/candles/bulk - Bulk create candlesGET /api/live-prices - Get all live pricesGET /api/live-prices/exchange/:exchange - Get live prices by exchangeGET /api/live-prices/type/:type - Get live prices by instrument typeGET /api/live-prices/:symbolId - Get live price for symbolPOST /api/live-prices - Create/update live pricePOST /api/live-prices/bulk - Bulk update live pricesDELETE /api/live-prices/:symbolId - Delete live priceThe database schema is managed through Sequelize migrations and models:
src/models/migrations/src/models/index.jsKey entities:
To update the database schema:
npx sequelize-cli migration:generate --name descriptionnpx sequelize-cli db:migratenpm start - Start production servernpm run dev - Start development server with auto-reloadnpm test - Run Jest test suitenpm run test:watch - Run tests in watch modenpm run migrate - Run database migrationsnpm run migrate:undo - Revert last migrationnpm run lint - Run ESLintnpm run lint:fix - Fix ESLint issuesThis project uses ESLint for code linting. Run npm run lint to check for issues and npm run lint:fix to automatically fix them.
The project uses Jest with Supertest for endpoint testing. Key features:
{ force: true } syncRun tests:
npm test # Run full test suite
npm run test:watch # Run in watch mode
We use Sequelize CLI for database migrations:
# Create new migration
npx sequelize-cli migration:generate --name your-migration-name
# Run pending migrations
npx sequelize-cli db:migrate
# Revert last migration
npx sequelize-cli db:migrate:undo
NODE_ENV=production in your environmentnpm start to start the production serverISC License - see LICENSE file for details.
For support or questions, please contact the development team.