app.js
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var express = require('express');
var app = express();
var fs = require('fs');
const fetch = require('node-fetch');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var sortingArr = function(data, ratio)
{
return data.sort(function(first, second)
{
var a = first[ratio];
var b = second[ratio];
return a > b ? -1 : a < b ? 1 : 0;
});
};
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 (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);
}
});
return promise;
}
var volumePerThreeMinArr = new Array();
function getThreeMinVolume()
{
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);
}
});
return promise;
}
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);
if (pumpingArr.length >= coinNameArr.length)
resolve(pumpingArr);
}
})
return promise;
}
// get
getWeekVolume().then(function(volArr){
getThreeMinVolume().then(function(minArr){
getResultArr(volArr, minArr).then(function(result){
//console.log(sortingArr(result, "pumpingRatio"));
res.send(sortingArr(result, "pumpingRatio"));
})
})
})
})
})
var server = app.listen(8082);
console.log("Server Created..");