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.

index.js 856B

123456789101112131415161718192021222324252627282930
  1. const { sequelize } = require('../config/database');
  2. const Symbol = require('./Symbol');
  3. const Candle1h = require('./Candle1h');
  4. const LivePrice = require('./LivePrice');
  5. // Define associations
  6. Symbol.hasMany(Candle1h, { foreignKey: 'symbolId', as: 'candles1h' });
  7. Candle1h.belongsTo(Symbol, { foreignKey: 'symbolId', as: 'symbol' });
  8. Symbol.hasOne(LivePrice, { foreignKey: 'symbolId', as: 'livePrice' });
  9. LivePrice.belongsTo(Symbol, { foreignKey: 'symbolId', as: 'livePriceSymbol' });
  10. // Sync database (only in development)
  11. if (process.env.NODE_ENV === 'development') {
  12. sequelize.sync({ alter: true })
  13. .then(() => {
  14. console.log('Database synchronized successfully.');
  15. })
  16. .catch((error) => {
  17. console.error('Error synchronizing database:', error);
  18. });
  19. }
  20. module.exports = {
  21. sequelize,
  22. Symbol,
  23. Candle1h,
  24. LivePrice
  25. };