Ddp

import { DDP } from 'meteor/ddp-client'
import { Mongo } from 'meteor/mongo'



const eCoinCore = DDP.connect('https://ecoincore.com');
const ExchangeRates = new Mongo.Collection('ExchangeRates', eCoinCore);
const SomeInmemCollection = new Mongo.Collection('ExchangeRates', { connection: null });



eCoinCore.onReconnect = function() {
  log.info("eCoinCore.onReconnect");
  log.info("eCoinCore.status()", eCoinCore.status())
};


eCoinCore._stream.on('message', function(raw_msg) {
  // log.info({raw_msg})
});


Meteor.setTimeout(() => {
  ExchangeRates.find().forEach((rate)=>{
    ingestRate(rate)
  });

  // Keep track of ExchangeRates.
  const cursor = ExchangeRates.find({});
  const handle = cursor.observeChanges({
    added(id, rate) {
      ingestRate(rate)
    },
    changed(id, rate) {
      ingestRate(rate)
    }
  });
}, 5 * 1000);




// Meteor.setTimeout(() => handle.stop(), 15 * 60 * 1000);



Router.route('/v1/price', function () {

  const req = this.request;
  const res = this.response;

  var ip = req.headers['x-real-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddress;
  log.debug(`price requested from ip:${ip}`);
  res.end(JSON.stringify(currentExchangeRates, null, 3));

}, {where: 'server'});        
Back to top