전현진

Add pumping ratio

......@@ -5,132 +5,109 @@ 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 promise = new Promise(function(resolve, reject)
var volumePerWeekArr = new Array();
function getWeekVolume()
{
for(j = 0; j < coinNameArr.length / 10; j++){
for(i = j * 10; i < (j + 1) * 10 && 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();
fetch(url, options)
.then(res => res.json())
.then(json => {
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){
resolve(volumePerWeekArr);
}
})
.catch(err => console.error('error:' + err));
},i*180);
})(i);
var promise = new Promise(function(resolve, reject)
{
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();
fetch(url, options)
.then(res => res.json())
.then(json => {
coinJson.coin = coinNameArr[i];
coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume;
volumePerWeekArr.push(coinJson);
if (volumePerWeekArr.length >= coinNameArr.length)
resolve(volumePerWeekArr);
})
.catch(err => console.error('error:' + err));
}, i*300);
})(i);
}
}
//if(volumePerWeekArr.length > coinNameArr.length){
// console.log(volumePerThreeMinArr.length)
// resolve(volumePerWeekArr);
//}
});
return promise;
}
});
return promise;
})
}
function getThreeMinVolume()
{
fs.readFile('coin_name2.txt', 'utf8', function(err,data){
coinNameArr = data.split(",");
var promise = new Promise(function(resolve, reject)
var volumePerThreeMinArr = new Array();
function getThreeMinVolume()
{
for(j = 0; j < coinNameArr.length / 10; j++){
for(i = j * 10; i < (j + 1) * 10 && 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();
fetch(url, options)
.then(res => res.json())
.then(json => {
coinJson.coin = coinNameArr[i];
coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume;
volumePerThreeMinArr.push(coinJson);
console.log(coinJson);
console.log(i)
})
.catch(err => console.error('error:' + err));
},i*180);
})(i);
var promise = new Promise(function(resolve, reject)
{
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();
fetch(url, options)
.then(res => res.json())
.then(json => {
coinJson.coin = coinNameArr[i];
coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume;
volumePerThreeMinArr.push(coinJson);
if (volumePerThreeMinArr.length >= coinNameArr.length)
resolve(volumePerThreeMinArr);
})
.catch(err => console.error('error:' + err));
}, i*300);
})(i);
}
}
if(volumePerThreeMinArr.length > coinNameArr.length){
console.log(volumePerThreeMinArr.length)
resolve(volumePerThreeMinArr);
}
});
return promise;
})
}
});
return promise;
}
async function getPumpingRatioArr()
{
await getWeekVolume();
await getThreeMinVolume();
await function()
{
console.log("함수 들어옴");
console.log(volumePerWeekArr);
console.log(volumePerThreeMinArr);
}
}
var pumpingArr = new Array();
function getResultArr(volArr, minArr)
{
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();
// get
getWeekVolume().then(function(volArr){
getThreeMinVolume().then(function(minArr){
getResultArr(volArr, minArr).then(function(result){
// fs.readFile('coin_name2.txt', 'utf8', function(err,data){
// coinNameArr = data.split(",");
res.send(result);
})
})
})
// async function getPumingRatioArr()
// {
// getThreeMinVolume();
// getWeekVolume();
// await getThreeMinVolume().then(function(volumePerThreeMinArr){ });
// await getWeekVolume().then(function(volumePerWeekArr){ });
// 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..");
console.log("Server Created..");
\ No newline at end of file
......