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.
|
|
9 сар өмнө | |
|---|---|---|
| config | 9 сар өмнө | |
| public | 9 сар өмнө | |
| routes | 9 сар өмнө | |
| src | 9 сар өмнө | |
| utils | 9 сар өмнө | |
| .env.example | 9 сар өмнө | |
| .gitignore | 9 сар өмнө | |
| README.md | 9 сар өмнө | |
| package.json | 9 сар өмнө |
A high-performance, enterprise-grade financial data API that provides comprehensive market information for 2013+ financial instruments through both RESTful endpoints and real-time WebSocket connections.
Market Data Service is a robust Node.js-based platform designed for financial applications requiring reliable, low-latency market data. The service delivers historical candlestick data with H1 (1-hour) timeframe granularity and enables real-time price streaming triggered by database updates.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ REST API │ │ WebSocket │ │ Database │
│ Endpoints │◄──►│ Service │◄──►│ Layer │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Request │ │ Real-time │ │ Data │
│ Validation │ │ Updates │ │ Persistence │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Clone the repository
git clone <repository-url>
cd market-data-service
Install dependencies
npm install
Environment Configuration
cp .env.example .env
Configure your .env file:
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=market_data
DB_USER=your_username
DB_PASSWORD=your_password
# Redis Configuration (Optional)
REDIS_HOST=localhost
REDIS_PORT=6379
# Server Configuration
PORT=3000
NODE_ENV=development
# Security
JWT_SECRET=your_jwt_secret
API_RATE_LIMIT_WINDOW=15
API_RATE_LIMIT_MAX=100
Database Setup
# Initialize database
npm run db:init
# Or run migrations
npm run db:migrate
Development Mode
npm run dev
Production Mode
npm start
The server will start on http://localhost:3000
GET /api/prices/history/:symbol?timeframe=H1&limit=100
GET /api/symbols
GET /api/prices/:symbol/latest
// Connect to WebSocket
const socket = io('http://localhost:3000');
// Subscribe to price updates
socket.emit('subscribe', { symbol: 'AAPL' });
// Listen for price updates
socket.on('price_update', (data) => {
console.log('Price update:', data);
});
// Subscribe to candlestick updates
socket.emit('subscribe_candles', { symbol: 'AAPL', timeframe: 'H1' });
// Listen for candlestick updates
socket.on('candlestick_update', (data) => {
console.log('Candlestick update:', data);
});
The service supports multiple database configurations through Sequelize ORM:
// config/database.js
module.exports = {
development: {
dialect: 'mysql', // or 'postgres', 'sqlite'
host: process.env.DB_HOST,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD
}
};
Configure API rate limiting in your environment:
API_RATE_LIMIT_WINDOW=15 # Time window in minutes
API_RATE_LIMIT_MAX=100 # Max requests per window
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm test candleValidation.test.js
GET /api/prices/history/:symbol
Parameters:
symbol (path): Financial instrument symboltimeframe (query, optional): Timeframe (H1, H4, D1) - defaults to H1limit (query, optional): Number of records - defaults to 100from (query, optional): Start date (ISO 8601)to (query, optional): End date (ISO 8601)Response:
{
"symbol": "AAPL",
"timeframe": "H1",
"data": [
{
"timestamp": "2023-10-15T10:00:00Z",
"open": 150.25,
"high": 151.80,
"low": 149.90,
"close": 151.20,
"volume": 1250000
}
]
}
GET /api/symbols
Response:
{
"symbols": [
{
"symbol": "AAPL",
"name": "Apple Inc.",
"market": "NASDAQ",
"sector": "Technology"
}
]
}
├── config/ # Database and configuration files
├── logs/ # Application logs
├── middleware/ # Express middleware
├── models/ # Database models
├── public/ # Static files
├── routes/ # API routes
├── services/ # Business logic services
├── src/ # Main application entry point
├── tests/ # Test files
└── utils/ # Utility functions
services/routes/models/tests/git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For support and questions: