전현진

Add pumping ratio

......@@ -5,20 +5,23 @@ const fetch = require('node-fetch');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var pumpingArr = new Array();
var volumePerWeekArr = new Array();
var volumePerThreeMinArr = new Array();
function getWeekVolume()
{
fs.readFile('coin_name2.txt', 'utf8', function(err,data){
app.get('/pumping', function(req, res) {
fs.readFile('coin_name.txt', 'utf8', function(err,data){
coinNameArr = data.split(",");
var volumePerWeekArr = new Array();
function getWeekVolume()
{
var promise = new Promise(function(resolve, reject)
{
for(j = 0; j < coinNameArr.length / 10; j++){
for(i = j * 10; i < (j + 1) * 10 && i < coinNameArr.length; i++){
(function(i){
setTimeout(function(){
for (i = 0; i < coinNameArr.length; ++i)
{
(function (i)
{
setTimeout(function () {
const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
var coinJson = new Object();
......@@ -28,37 +31,28 @@ function getWeekVolume()
coinJson.coin = coinNameArr[i];
coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume;
volumePerWeekArr.push(coinJson);
console.log(coinJson);
console.log(i)
if(volumePerWeekArr.length>coinNameArr.length){
if (volumePerWeekArr.length >= coinNameArr.length)
resolve(volumePerWeekArr);
}
})
.catch(err => console.error('error:' + err));
},i*180);
}, i*300);
})(i);
}
}
//if(volumePerWeekArr.length > coinNameArr.length){
// console.log(volumePerThreeMinArr.length)
// resolve(volumePerWeekArr);
//}
});
return promise;
})
}
}
function getThreeMinVolume()
{
fs.readFile('coin_name2.txt', 'utf8', function(err,data){
coinNameArr = data.split(",");
var volumePerThreeMinArr = new Array();
function getThreeMinVolume()
{
var promise = new Promise(function(resolve, reject)
{
for(j = 0; j < coinNameArr.length / 10; j++){
for(i = j * 10; i < (j + 1) * 10 && i < coinNameArr.length; i++){
(function(i){
setTimeout(function(){
for (i = 0; i < coinNameArr.length; ++i)
{
(function (i)
{
setTimeout(function () {
const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
var coinJson = new Object();
......@@ -68,69 +62,52 @@ function getThreeMinVolume()
coinJson.coin = coinNameArr[i];
coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume;
volumePerThreeMinArr.push(coinJson);
console.log(coinJson);
console.log(i)
if (volumePerThreeMinArr.length >= coinNameArr.length)
resolve(volumePerThreeMinArr);
})
.catch(err => console.error('error:' + err));
},i*180);
}, i*300);
})(i);
}
}
if(volumePerThreeMinArr.length > coinNameArr.length){
console.log(volumePerThreeMinArr.length)
resolve(volumePerThreeMinArr);
}
});
});
return promise;
})
}
}
async function getPumpingRatioArr()
{
await getWeekVolume();
await getThreeMinVolume();
await function()
var pumpingArr = new Array();
function getResultArr(volArr, minArr)
{
console.log("함수 들어옴");
console.log(volumePerWeekArr);
console.log(volumePerThreeMinArr);
var promise = new Promise(function(resolve, reject)
{
for (var i = 0; i < coinNameArr.length; i++)
{
var coinJson = new Object();
coinJson.name = coinNameArr[i];
coinJson.pumpingRatio = minArr[i].tradeVolumePerThreeMin / volArr[i].tradeVolumePerWeek * 1000000
pumpingArr.push(coinJson);
console.log(coinJson);
if (pumpingArr.length >= coinNameArr.length)
resolve(pumpingArr);
}
})
return promise;
}
}
app.get('/pumping', function(req, res) {
getPumpingRatioArr();
//getThreeMinVolume();
//getWeekVolume();
// fs.readFile('coin_name2.txt', 'utf8', function(err,data){
// coinNameArr = data.split(",");
// get
getWeekVolume().then(function(volArr){
getThreeMinVolume().then(function(minArr){
getResultArr(volArr, minArr).then(function(result){
// async function getPumingRatioArr()
// {
// getThreeMinVolume();
// getWeekVolume();
// await getThreeMinVolume().then(function(volumePerThreeMinArr){ });
// await getWeekVolume().then(function(volumePerWeekArr){ });
res.send(result);
// var coinJson = new Object();
// for (var i = 0; i < coinNameArr.length; i++)
// {
// coinJson.name = coinNameArr[i];
// coinJson.pumpingRatio = volumePerThreeMinArr[i].tradeVolumePerThreeMin / volumePerWeekArr[i].tradeVolumePerWeek * 100
// pumpingArr.push(coinJson);
// console.log(coinJson);
// }
// }
})
})
})
// getPumingRatioArr().then(function(pumpingArr){
// res.send(pumpingArr);
// });
// })
})
})
var server = app.listen(8082);
console.log("Server Created..");
\ No newline at end of file
......