Showing
1 changed file
with
88 additions
and
111 deletions
... | @@ -5,132 +5,109 @@ const fetch = require('node-fetch'); | ... | @@ -5,132 +5,109 @@ 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(","); |
16 | - var promise = new Promise(function(resolve, reject) | 13 | + |
14 | + | ||
15 | + var volumePerWeekArr = new Array(); | ||
16 | + function getWeekVolume() | ||
17 | { | 17 | { |
18 | - for(j = 0; j < coinNameArr.length / 10; j++){ | 18 | + var promise = new Promise(function(resolve, reject) |
19 | - for(i = j * 10; i < (j + 1) * 10 && i < coinNameArr.length; i++){ | 19 | + { |
20 | - (function(i){ | 20 | + for (i = 0; i < coinNameArr.length; ++i) |
21 | - setTimeout(function(){ | 21 | + { |
22 | - const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1'; | 22 | + (function (i) |
23 | - const options = {method: 'GET', headers: {Accept: 'application/json'}}; | 23 | + { |
24 | - var coinJson = new Object(); | 24 | + setTimeout(function () { |
25 | - fetch(url, options) | 25 | + const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1'; |
26 | - .then(res => res.json()) | 26 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; |
27 | - .then(json => { | 27 | + var coinJson = new Object(); |
28 | - coinJson.coin = coinNameArr[i]; | 28 | + fetch(url, options) |
29 | - coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume; | 29 | + .then(res => res.json()) |
30 | - volumePerWeekArr.push(coinJson); | 30 | + .then(json => { |
31 | - console.log(coinJson); | 31 | + coinJson.coin = coinNameArr[i]; |
32 | - console.log(i) | 32 | + coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume; |
33 | - if(volumePerWeekArr.length>coinNameArr.length){ | 33 | + volumePerWeekArr.push(coinJson); |
34 | - resolve(volumePerWeekArr); | 34 | + if (volumePerWeekArr.length >= coinNameArr.length) |
35 | - } | 35 | + resolve(volumePerWeekArr); |
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 | - } | 41 | + }); |
42 | - //if(volumePerWeekArr.length > coinNameArr.length){ | 42 | + return promise; |
43 | - // console.log(volumePerThreeMinArr.length) | 43 | + } |
44 | - // resolve(volumePerWeekArr); | ||
45 | - //} | ||
46 | 44 | ||
47 | - }); | ||
48 | - return promise; | ||
49 | - }) | ||
50 | -} | ||
51 | 45 | ||
52 | -function getThreeMinVolume() | 46 | + var volumePerThreeMinArr = new Array(); |
53 | -{ | 47 | + function getThreeMinVolume() |
54 | - fs.readFile('coin_name2.txt', 'utf8', function(err,data){ | ||
55 | - coinNameArr = data.split(","); | ||
56 | - var promise = new Promise(function(resolve, reject) | ||
57 | { | 48 | { |
58 | - for(j = 0; j < coinNameArr.length / 10; j++){ | 49 | + var promise = new Promise(function(resolve, reject) |
59 | - for(i = j * 10; i < (j + 1) * 10 && i < coinNameArr.length; i++){ | 50 | + { |
60 | - (function(i){ | 51 | + for (i = 0; i < coinNameArr.length; ++i) |
61 | - setTimeout(function(){ | 52 | + { |
62 | - const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1'; | 53 | + (function (i) |
63 | - const options = {method: 'GET', headers: {Accept: 'application/json'}}; | 54 | + { |
64 | - var coinJson = new Object(); | 55 | + setTimeout(function () { |
65 | - fetch(url, options) | 56 | + const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1'; |
66 | - .then(res => res.json()) | 57 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; |
67 | - .then(json => { | 58 | + var coinJson = new Object(); |
68 | - coinJson.coin = coinNameArr[i]; | 59 | + fetch(url, options) |
69 | - coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume; | 60 | + .then(res => res.json()) |
70 | - volumePerThreeMinArr.push(coinJson); | 61 | + .then(json => { |
71 | - console.log(coinJson); | 62 | + coinJson.coin = coinNameArr[i]; |
72 | - console.log(i) | 63 | + coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume; |
73 | - }) | 64 | + volumePerThreeMinArr.push(coinJson); |
74 | - .catch(err => console.error('error:' + err)); | 65 | + if (volumePerThreeMinArr.length >= coinNameArr.length) |
75 | - },i*180); | 66 | + resolve(volumePerThreeMinArr); |
76 | - })(i); | 67 | + }) |
68 | + .catch(err => console.error('error:' + err)); | ||
69 | + }, i*300); | ||
70 | + })(i); | ||
77 | } | 71 | } |
78 | - } | ||
79 | - if(volumePerThreeMinArr.length > coinNameArr.length){ | ||
80 | - console.log(volumePerThreeMinArr.length) | ||
81 | - resolve(volumePerThreeMinArr); | ||
82 | - } | ||
83 | - }); | ||
84 | 72 | ||
85 | - return promise; | 73 | + }); |
86 | - }) | 74 | + return promise; |
87 | -} | 75 | + } |
88 | 76 | ||
89 | -async function getPumpingRatioArr() | ||
90 | -{ | ||
91 | - await getWeekVolume(); | ||
92 | - await getThreeMinVolume(); | ||
93 | 77 | ||
94 | - await function() | 78 | + var pumpingArr = new Array(); |
95 | - { | 79 | + function getResultArr(volArr, minArr) |
96 | - console.log("함수 들어옴"); | 80 | + { |
97 | - console.log(volumePerWeekArr); | 81 | + var promise = new Promise(function(resolve, reject) |
98 | - console.log(volumePerThreeMinArr); | 82 | + { |
99 | - } | 83 | + for (var i = 0; i < coinNameArr.length; i++) |
100 | -} | 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; | ||
95 | + } | ||
101 | 96 | ||
102 | -app.get('/pumping', function(req, res) { | ||
103 | 97 | ||
104 | - getPumpingRatioArr(); | 98 | + // get |
105 | - //getThreeMinVolume(); | 99 | + getWeekVolume().then(function(volArr){ |
106 | - //getWeekVolume(); | 100 | + getThreeMinVolume().then(function(minArr){ |
101 | + getResultArr(volArr, minArr).then(function(result){ | ||
107 | 102 | ||
108 | - // fs.readFile('coin_name2.txt', 'utf8', function(err,data){ | 103 | + res.send(result); |
109 | - // coinNameArr = data.split(","); | 104 | + |
105 | + }) | ||
106 | + }) | ||
107 | + }) | ||
110 | 108 | ||
111 | - | ||
112 | - // async function getPumingRatioArr() | ||
113 | - // { | ||
114 | - // getThreeMinVolume(); | ||
115 | - // getWeekVolume(); | ||
116 | - // await getThreeMinVolume().then(function(volumePerThreeMinArr){ }); | ||
117 | - // await getWeekVolume().then(function(volumePerWeekArr){ }); | ||
118 | - | ||
119 | - // var coinJson = new Object(); | ||
120 | - // for (var i = 0; i < coinNameArr.length; i++) | ||
121 | - // { | ||
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 | - | ||
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 | ... | ... |
-
Please register or login to post a comment