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