전현진

Add pumping ratio

...@@ -5,20 +5,23 @@ const fetch = require('node-fetch'); ...@@ -5,20 +5,23 @@ const fetch = require('node-fetch');
5 var bodyParser = require('body-parser'); 5 var bodyParser = require('body-parser');
6 app.use(bodyParser.urlencoded({ extended: false })); 6 app.use(bodyParser.urlencoded({ extended: false }));
7 app.use(bodyParser.json()); 7 app.use(bodyParser.json());
8 -var pumpingArr = new Array();
9 -var volumePerWeekArr = new Array();
10 -var volumePerThreeMinArr = new Array();
11 8
12 -function getWeekVolume() 9 +
13 -{ 10 +app.get('/pumping', function(req, res) {
14 - fs.readFile('coin_name2.txt', 'utf8', function(err,data){ 11 + fs.readFile('coin_name.txt', 'utf8', function(err,data){
15 coinNameArr = data.split(","); 12 coinNameArr = data.split(",");
13 +
14 +
15 + var volumePerWeekArr = new Array();
16 + function getWeekVolume()
17 + {
16 var promise = new Promise(function(resolve, reject) 18 var promise = new Promise(function(resolve, reject)
17 { 19 {
18 - for(j = 0; j < coinNameArr.length / 10; j++){ 20 + for (i = 0; i < coinNameArr.length; ++i)
19 - for(i = j * 10; i < (j + 1) * 10 && i < coinNameArr.length; i++){ 21 + {
20 - (function(i){ 22 + (function (i)
21 - setTimeout(function(){ 23 + {
24 + setTimeout(function () {
22 const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1'; 25 const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1';
23 const options = {method: 'GET', headers: {Accept: 'application/json'}}; 26 const options = {method: 'GET', headers: {Accept: 'application/json'}};
24 var coinJson = new Object(); 27 var coinJson = new Object();
...@@ -28,37 +31,28 @@ function getWeekVolume() ...@@ -28,37 +31,28 @@ function getWeekVolume()
28 coinJson.coin = coinNameArr[i]; 31 coinJson.coin = coinNameArr[i];
29 coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume; 32 coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume;
30 volumePerWeekArr.push(coinJson); 33 volumePerWeekArr.push(coinJson);
31 - console.log(coinJson); 34 + if (volumePerWeekArr.length >= coinNameArr.length)
32 - console.log(i)
33 - if(volumePerWeekArr.length>coinNameArr.length){
34 resolve(volumePerWeekArr); 35 resolve(volumePerWeekArr);
35 - }
36 }) 36 })
37 .catch(err => console.error('error:' + err)); 37 .catch(err => console.error('error:' + err));
38 - },i*180); 38 + }, i*300);
39 })(i); 39 })(i);
40 } 40 }
41 - }
42 - //if(volumePerWeekArr.length > coinNameArr.length){
43 - // console.log(volumePerThreeMinArr.length)
44 - // resolve(volumePerWeekArr);
45 - //}
46 -
47 }); 41 });
48 return promise; 42 return promise;
49 - }) 43 + }
50 -}
51 44
52 -function getThreeMinVolume() 45 +
53 -{ 46 + var volumePerThreeMinArr = new Array();
54 - fs.readFile('coin_name2.txt', 'utf8', function(err,data){ 47 + function getThreeMinVolume()
55 - coinNameArr = data.split(","); 48 + {
56 var promise = new Promise(function(resolve, reject) 49 var promise = new Promise(function(resolve, reject)
57 { 50 {
58 - for(j = 0; j < coinNameArr.length / 10; j++){ 51 + for (i = 0; i < coinNameArr.length; ++i)
59 - for(i = j * 10; i < (j + 1) * 10 && i < coinNameArr.length; i++){ 52 + {
60 - (function(i){ 53 + (function (i)
61 - setTimeout(function(){ 54 + {
55 + setTimeout(function () {
62 const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1'; 56 const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1';
63 const options = {method: 'GET', headers: {Accept: 'application/json'}}; 57 const options = {method: 'GET', headers: {Accept: 'application/json'}};
64 var coinJson = new Object(); 58 var coinJson = new Object();
...@@ -68,69 +62,52 @@ function getThreeMinVolume() ...@@ -68,69 +62,52 @@ function getThreeMinVolume()
68 coinJson.coin = coinNameArr[i]; 62 coinJson.coin = coinNameArr[i];
69 coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume; 63 coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume;
70 volumePerThreeMinArr.push(coinJson); 64 volumePerThreeMinArr.push(coinJson);
71 - console.log(coinJson); 65 + if (volumePerThreeMinArr.length >= coinNameArr.length)
72 - console.log(i) 66 + resolve(volumePerThreeMinArr);
73 }) 67 })
74 .catch(err => console.error('error:' + err)); 68 .catch(err => console.error('error:' + err));
75 - },i*180); 69 + }, i*300);
76 })(i); 70 })(i);
77 } 71 }
78 - }
79 - if(volumePerThreeMinArr.length > coinNameArr.length){
80 - console.log(volumePerThreeMinArr.length)
81 - resolve(volumePerThreeMinArr);
82 - }
83 - });
84 72
73 + });
85 return promise; 74 return promise;
86 - }) 75 + }
87 -}
88 76
89 -async function getPumpingRatioArr()
90 -{
91 - await getWeekVolume();
92 - await getThreeMinVolume();
93 77
94 - await function() 78 + var pumpingArr = new Array();
79 + function getResultArr(volArr, minArr)
95 { 80 {
96 - console.log("함수 들어옴"); 81 + var promise = new Promise(function(resolve, reject)
97 - console.log(volumePerWeekArr); 82 + {
98 - console.log(volumePerThreeMinArr); 83 + for (var i = 0; i < coinNameArr.length; i++)
84 + {
85 + var coinJson = new Object();
86 + coinJson.name = coinNameArr[i];
87 + coinJson.pumpingRatio = minArr[i].tradeVolumePerThreeMin / volArr[i].tradeVolumePerWeek * 1000000
88 + pumpingArr.push(coinJson);
89 + console.log(coinJson);
90 + if (pumpingArr.length >= coinNameArr.length)
91 + resolve(pumpingArr);
92 + }
93 + })
94 + return promise;
99 } 95 }
100 -}
101 -
102 -app.get('/pumping', function(req, res) {
103 -
104 - getPumpingRatioArr();
105 - //getThreeMinVolume();
106 - //getWeekVolume();
107 96
108 - // fs.readFile('coin_name2.txt', 'utf8', function(err,data){
109 - // coinNameArr = data.split(",");
110 97
98 + // get
99 + getWeekVolume().then(function(volArr){
100 + getThreeMinVolume().then(function(minArr){
101 + getResultArr(volArr, minArr).then(function(result){
111 102
112 - // async function getPumingRatioArr() 103 + res.send(result);
113 - // {
114 - // getThreeMinVolume();
115 - // getWeekVolume();
116 - // await getThreeMinVolume().then(function(volumePerThreeMinArr){ });
117 - // await getWeekVolume().then(function(volumePerWeekArr){ });
118 104
119 - // var coinJson = new Object(); 105 + })
120 - // for (var i = 0; i < coinNameArr.length; i++) 106 + })
121 - // { 107 + })
122 - // coinJson.name = coinNameArr[i];
123 - // coinJson.pumpingRatio = volumePerThreeMinArr[i].tradeVolumePerThreeMin / volumePerWeekArr[i].tradeVolumePerWeek * 100
124 - // pumpingArr.push(coinJson);
125 - // console.log(coinJson);
126 - // }
127 - // }
128 108
129 109
130 - // getPumingRatioArr().then(function(pumpingArr){ 110 + })
131 - // res.send(pumpingArr);
132 - // });
133 - // })
134 }) 111 })
135 var server = app.listen(8082); 112 var server = app.listen(8082);
136 console.log("Server Created.."); 113 console.log("Server Created..");
...\ No newline at end of file ...\ No newline at end of file
......