111

111


const Poloniex = require('poloniex-api-node');

var fs = require('fs');

var path = require('path');

var config = require('./config');

var pair = require('./pair');

var sql = require('mssql');


let poloniex = new Poloniex();


if(config.enable_returnTicker==1){

let timerId = setInterval(function() {

poloniex.returnTicker((err, ticker) => {

if (err) {

console.log(err.message);

} else {

let now = new Date().toLocaleString();

let file_name = now+'.txt';

file_name = file_name.replace(/:/g,'_');

let path_src = path.join(config.dir_returnTicker,file_name);

fs.open(path_src,'w',function(err,fd){

if(err){console.log(err.message);return;};


fs.write(fd,JSON.stringify(ticker),function(err){

if(err){console.log(err.message)};

fs.close(fd,function(err){

if(err){console.log(err.message)};

});

});

});

}

});

}, config.interval_returnTicker);

}


if(config.enable_returnOrderBook==1){

let timerId = setInterval(function() {

poloniex.returnOrderBook('all',10,(err,orrderBook) => {

pair.forEach(element => {

for(key in orrderBook){

if(key == element){

if (err) {

console.log(err.message);

} else {

let now = new Date().toLocaleString();

let file_name = key+"_"+now+'.txt';

file_name = file_name.replace(/:/g,'_');

let path_src = path.join(config.dir_returnOrderBook,key,file_name);

fs.open(path_src,'w',function(err,fd){

if(err){console.log(err.message);return;};

let mess = JSON.stringify(orrderBook[key]);

fs.write(fd,mess,function(err){

if(err){console.log(err.message)};

fs.close(fd,function(err){

if(err){console.log(err.message)};

});

});

});

}

}


}

});

})

},config.interval_returnOrderBook);

}


if(config.enable_returnTradeHistory==1){

let timerId = setInterval(function() {

let time = new Date();

let ms = time.getMilliseconds();

pair.forEach(element => {

poloniex.returnTradeHistory(element,false,false,false,(err,tradeHistory) => {

let now = new Date().toLocaleString();

let file_name = element+"_"+now+'.txt';

file_name = file_name.replace(/:/g,'_');

let path_src = path.join(config.dir_returnTradeHistory,element,file_name);

sleep(config.value_min_req_interval);


fs.open(path_src,'w',function(err,fd){

if(err){console.log(err.message);return;};

let mess = JSON.stringify(tradeHistory);

fs.write(fd,mess,function(err){

if(err){console.log(err.message)};

fs.close(fd,function(err){

if(err){console.log(err.message)};

});

});

});

})

});

},config.interval_returnTradeHistory);

}

console.log('poloniex agregator is enable:\nвся информация собирается в папке data');

function sleep(millis) {

var t = (new Date()).getTime();

var i = 0;

while (((new Date()).getTime() - t) < millis) {

i++;

}

}