Showing
2 changed files
with
152 additions
and
198 deletions
... | @@ -24,9 +24,13 @@ app.post('/hook', function (req, res) { | ... | @@ -24,9 +24,13 @@ app.post('/hook', function (req, res) { |
24 | console.log('[request]', req.body); | 24 | console.log('[request]', req.body); |
25 | console.log('[request source] ', source); | 25 | console.log('[request source] ', source); |
26 | console.log('[request message]', message); | 26 | console.log('[request message]', message); |
27 | + | ||
27 | if(message.text === '김프'){ | 28 | if(message.text === '김프'){ |
28 | command = '김프'; | 29 | command = '김프'; |
29 | } | 30 | } |
31 | + else if (message.text === '거래량비율') | ||
32 | + volumePumpingRatioThreeMinutePerWeek(eventObj.replyToken, message.text); | ||
33 | + | ||
30 | else{ | 34 | else{ |
31 | if(command === '김프'){ | 35 | if(command === '김프'){ |
32 | kimp(eventObj.replyToken, message.text); | 36 | kimp(eventObj.replyToken, message.text); |
... | @@ -125,6 +129,154 @@ function compare_price(replyToken, message, upbitPrice){ | ... | @@ -125,6 +129,154 @@ function compare_price(replyToken, message, upbitPrice){ |
125 | }); | 129 | }); |
126 | } | 130 | } |
127 | 131 | ||
132 | +function volumePumpingRatioThreeMinutePerWeek(replyToken, message) | ||
133 | +{ | ||
134 | + fs.readFile('coin_name.txt', 'utf8', function(err,data){ | ||
135 | + coinNameArr = data.split(","); | ||
136 | + | ||
137 | + | ||
138 | + var volumePerWeekArr = new Array(); | ||
139 | + function getWeekVolume() | ||
140 | + { | ||
141 | + var promise = new Promise(function(resolve, reject) | ||
142 | + { | ||
143 | + for (i = 0; i < coinNameArr.length; ++i) | ||
144 | + { | ||
145 | + (function (i) | ||
146 | + { | ||
147 | + setTimeout(function () { | ||
148 | + const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1'; | ||
149 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
150 | + var coinJson = new Object(); | ||
151 | + fetch(url, options) | ||
152 | + .then(res => res.json()) | ||
153 | + .then(json => { | ||
154 | + coinJson.coin = coinNameArr[i]; | ||
155 | + coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume; | ||
156 | + volumePerWeekArr.push(coinJson); | ||
157 | + console.log(coinJson); | ||
158 | + if (volumePerWeekArr.length >= coinNameArr.length) | ||
159 | + resolve(volumePerWeekArr); | ||
160 | + }) | ||
161 | + .catch(err => console.error('error:' + err)); | ||
162 | + }, i*220); | ||
163 | + })(i); | ||
164 | + } | ||
165 | + }); | ||
166 | + return promise; | ||
167 | + } | ||
168 | + | ||
169 | + | ||
170 | + var volumePerThreeMinArr = new Array(); | ||
171 | + function getThreeMinVolume() | ||
172 | + { | ||
173 | + var promise = new Promise(function(resolve, reject) | ||
174 | + { | ||
175 | + for (i = 0; i < coinNameArr.length; ++i) | ||
176 | + { | ||
177 | + (function (i) | ||
178 | + { | ||
179 | + setTimeout(function () { | ||
180 | + const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1'; | ||
181 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
182 | + var coinJson = new Object(); | ||
183 | + fetch(url, options) | ||
184 | + .then(res => res.json()) | ||
185 | + .then(json => { | ||
186 | + coinJson.coin = coinNameArr[i]; | ||
187 | + coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume; | ||
188 | + volumePerThreeMinArr.push(coinJson); | ||
189 | + console.log(coinJson); | ||
190 | + if (volumePerThreeMinArr.length >= coinNameArr.length) | ||
191 | + resolve(volumePerThreeMinArr); | ||
192 | + }) | ||
193 | + .catch(err => console.error('error:' + err)); | ||
194 | + }, i*220); | ||
195 | + })(i); | ||
196 | + } | ||
197 | + | ||
198 | + }); | ||
199 | + return promise; | ||
200 | + } | ||
201 | + | ||
202 | + | ||
203 | + var pumpingArr = new Array(); | ||
204 | + function getResultArr(volArr, minArr) | ||
205 | + { | ||
206 | + var promise = new Promise(function(resolve, reject) | ||
207 | + { | ||
208 | + for (var i = 0; i < coinNameArr.length; i++) | ||
209 | + { | ||
210 | + var coinJson = new Object(); | ||
211 | + coinJson.name = coinNameArr[i]; | ||
212 | + coinJson.pumpingRatio = minArr[i].tradeVolumePerThreeMin / volArr[i].tradeVolumePerWeek * 1000000 | ||
213 | + pumpingArr.push(coinJson); | ||
214 | + if (pumpingArr.length >= coinNameArr.length) | ||
215 | + resolve(pumpingArr); | ||
216 | + } | ||
217 | + }) | ||
218 | + return promise; | ||
219 | + } | ||
220 | + | ||
221 | + function sortingArr(data, ratio) | ||
222 | + { | ||
223 | + var promise = new Promise(function(resolve, reject) | ||
224 | + { | ||
225 | + resolve(data.sort(function(first, second) | ||
226 | + { | ||
227 | + var a = first[ratio]; | ||
228 | + var b = second[ratio]; | ||
229 | + | ||
230 | + return a > b ? -1 : a < b ? 1 : 0; | ||
231 | + })) | ||
232 | + }); | ||
233 | + | ||
234 | + return promise; | ||
235 | + }; | ||
236 | + | ||
237 | + getWeekVolume().then(function(volArr){ | ||
238 | + getThreeMinVolume().then(function(minArr){ | ||
239 | + getResultArr(volArr, minArr).then(function(result){ | ||
240 | + sortingArr(result, "pumpingRatio").then(function(finalArr){ | ||
241 | + | ||
242 | + console.log(finalArr); | ||
243 | + request.post( | ||
244 | + { | ||
245 | + url: TARGET_URL, | ||
246 | + headers: { | ||
247 | + 'Authorization': `Bearer ${TOKEN}` | ||
248 | + }, | ||
249 | + json: { | ||
250 | + "replyToken":replyToken, | ||
251 | + "messages": [ | ||
252 | + { | ||
253 | + "type":"text", | ||
254 | + "text": finalArr[0].name + ' : ' + String(finalArr[0].pumpingRatio) + '\n' | ||
255 | + + finalArr[1].name + ' : ' + String(finalArr[1].pumpingRatio) + '\n' | ||
256 | + + finalArr[2].name + ' : ' + String(finalArr[2].pumpingRatio) + '\n' | ||
257 | + + finalArr[3].name + ' : ' + String(finalArr[3].pumpingRatio) + '\n' | ||
258 | + + finalArr[4].name + ' : ' + String(finalArr[4].pumpingRatio) + '\n' | ||
259 | + + finalArr[5].name + ' : ' + String(finalArr[5].pumpingRatio) + '\n' | ||
260 | + + finalArr[6].name + ' : ' + String(finalArr[6].pumpingRatio) + '\n' | ||
261 | + + finalArr[7].name + ' : ' + String(finalArr[7].pumpingRatio) + '\n' | ||
262 | + + finalArr[8].name + ' : ' + String(finalArr[8].pumpingRatio) + '\n' | ||
263 | + + finalArr[9].name + ' : ' + String(finalArr[9].pumpingRatio) + '\n' | ||
264 | + } | ||
265 | + ] | ||
266 | + } | ||
267 | + },(error, response, body) => { | ||
268 | + console.log(body) | ||
269 | + }); | ||
270 | + res.sendStatus(200); | ||
271 | + | ||
272 | + }) | ||
273 | + }) | ||
274 | + }) | ||
275 | + }) | ||
276 | + }) | ||
277 | +} | ||
278 | + | ||
279 | + | ||
128 | try { | 280 | try { |
129 | const option = { | 281 | const option = { |
130 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 282 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
line.js
deleted
100644 → 0
1 | -var express = require('express'); | ||
2 | -const request = require('request');const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
3 | -const TOKEN = '/* 수정 */'; | ||
4 | -const fs = require('fs'); | ||
5 | -const path = require('path'); | ||
6 | -const HTTPS = require('https'); | ||
7 | -const fetch = require('node-fetch'); | ||
8 | -const rp = require('request-promise'); | ||
9 | -const domain = "/* 수정 */" | ||
10 | -const sslport = 23023; | ||
11 | -const bodyParser = require('body-parser'); | ||
12 | -var app = express(); | ||
13 | -var command = ''; | ||
14 | -app.use(bodyParser.json()); | ||
15 | - | ||
16 | - | ||
17 | -app.post('/hook', function (req, res) { | ||
18 | - | ||
19 | - var eventObj = req.body.events[0]; | ||
20 | - var source = eventObj.source; | ||
21 | - var message = eventObj.message; | ||
22 | - // request log | ||
23 | - console.log('======================', new Date() ,'======================'); | ||
24 | - console.log('[request]', req.body); | ||
25 | - console.log('[request source] ', source); | ||
26 | - console.log('[request message]', message); | ||
27 | - | ||
28 | - /*=============================================================*/ | ||
29 | - | ||
30 | - if(message.text === '거래량비율') | ||
31 | - volumePumpingRatioThreeMinutePerWeek(eventObj.replyToken, message.text); | ||
32 | - | ||
33 | - /*=============================================================*/ | ||
34 | - | ||
35 | - res.sendStatus(200); | ||
36 | -}); | ||
37 | - | ||
38 | -function volumePumpingRatioThreeMinutePerWeek(replyToken, message) | ||
39 | -{ | ||
40 | - fs.readFile('coin_name.txt', 'utf8', function(err,data){ | ||
41 | - coinNameArr = data.split(","); | ||
42 | - | ||
43 | - | ||
44 | - var volumePerWeekArr = new Array(); | ||
45 | - function getWeekVolume() | ||
46 | - { | ||
47 | - var promise = new Promise(function(resolve, reject) | ||
48 | - { | ||
49 | - for (i = 0; i < coinNameArr.length; ++i) | ||
50 | - { | ||
51 | - (function (i) | ||
52 | - { | ||
53 | - setTimeout(function () { | ||
54 | - const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[i]+'&count=1'; | ||
55 | - const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
56 | - var coinJson = new Object(); | ||
57 | - fetch(url, options) | ||
58 | - .then(res => res.json()) | ||
59 | - .then(json => { | ||
60 | - coinJson.coin = coinNameArr[i]; | ||
61 | - coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume; | ||
62 | - volumePerWeekArr.push(coinJson); | ||
63 | - console.log(coinJson); | ||
64 | - if (volumePerWeekArr.length >= coinNameArr.length) | ||
65 | - resolve(volumePerWeekArr); | ||
66 | - }) | ||
67 | - .catch(err => console.error('error:' + err)); | ||
68 | - }, i*220); | ||
69 | - })(i); | ||
70 | - } | ||
71 | - }); | ||
72 | - return promise; | ||
73 | - } | ||
74 | - | ||
75 | - | ||
76 | - var volumePerThreeMinArr = new Array(); | ||
77 | - function getThreeMinVolume() | ||
78 | - { | ||
79 | - var promise = new Promise(function(resolve, reject) | ||
80 | - { | ||
81 | - for (i = 0; i < coinNameArr.length; ++i) | ||
82 | - { | ||
83 | - (function (i) | ||
84 | - { | ||
85 | - setTimeout(function () { | ||
86 | - const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[i]+'&count=1'; | ||
87 | - const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
88 | - var coinJson = new Object(); | ||
89 | - fetch(url, options) | ||
90 | - .then(res => res.json()) | ||
91 | - .then(json => { | ||
92 | - coinJson.coin = coinNameArr[i]; | ||
93 | - coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume; | ||
94 | - volumePerThreeMinArr.push(coinJson); | ||
95 | - console.log(coinJson); | ||
96 | - if (volumePerThreeMinArr.length >= coinNameArr.length) | ||
97 | - resolve(volumePerThreeMinArr); | ||
98 | - }) | ||
99 | - .catch(err => console.error('error:' + err)); | ||
100 | - }, i*220); | ||
101 | - })(i); | ||
102 | - } | ||
103 | - | ||
104 | - }); | ||
105 | - return promise; | ||
106 | - } | ||
107 | - | ||
108 | - | ||
109 | - var pumpingArr = new Array(); | ||
110 | - function getResultArr(volArr, minArr) | ||
111 | - { | ||
112 | - var promise = new Promise(function(resolve, reject) | ||
113 | - { | ||
114 | - for (var i = 0; i < coinNameArr.length; i++) | ||
115 | - { | ||
116 | - var coinJson = new Object(); | ||
117 | - coinJson.name = coinNameArr[i]; | ||
118 | - coinJson.pumpingRatio = minArr[i].tradeVolumePerThreeMin / volArr[i].tradeVolumePerWeek * 1000000 | ||
119 | - pumpingArr.push(coinJson); | ||
120 | - if (pumpingArr.length >= coinNameArr.length) | ||
121 | - resolve(pumpingArr); | ||
122 | - } | ||
123 | - }) | ||
124 | - return promise; | ||
125 | - } | ||
126 | - | ||
127 | - function sortingArr(data, ratio) | ||
128 | - { | ||
129 | - var promise = new Promise(function(resolve, reject) | ||
130 | - { | ||
131 | - resolve(data.sort(function(first, second) | ||
132 | - { | ||
133 | - var a = first[ratio]; | ||
134 | - var b = second[ratio]; | ||
135 | - | ||
136 | - return a > b ? -1 : a < b ? 1 : 0; | ||
137 | - })) | ||
138 | - }); | ||
139 | - | ||
140 | - return promise; | ||
141 | - }; | ||
142 | - | ||
143 | - getWeekVolume().then(function(volArr){ | ||
144 | - getThreeMinVolume().then(function(minArr){ | ||
145 | - getResultArr(volArr, minArr).then(function(result){ | ||
146 | - sortingArr(result, "pumpingRatio").then(function(finalArr){ | ||
147 | - | ||
148 | - console.log(finalArr); | ||
149 | - request.post( | ||
150 | - { | ||
151 | - url: TARGET_URL, | ||
152 | - headers: { | ||
153 | - 'Authorization': `Bearer ${TOKEN}` | ||
154 | - }, | ||
155 | - json: { | ||
156 | - "replyToken":replyToken, | ||
157 | - "messages": [ | ||
158 | - { | ||
159 | - "type":"text", | ||
160 | - "text": finalArr[0].name + ' : ' + String(finalArr[0].pumpingRatio) + '\n' | ||
161 | - + finalArr[1].name + ' : ' + String(finalArr[1].pumpingRatio) + '\n' | ||
162 | - + finalArr[2].name + ' : ' + String(finalArr[2].pumpingRatio) + '\n' | ||
163 | - + finalArr[3].name + ' : ' + String(finalArr[3].pumpingRatio) + '\n' | ||
164 | - + finalArr[4].name + ' : ' + String(finalArr[4].pumpingRatio) + '\n' | ||
165 | - + finalArr[5].name + ' : ' + String(finalArr[5].pumpingRatio) + '\n' | ||
166 | - + finalArr[6].name + ' : ' + String(finalArr[6].pumpingRatio) + '\n' | ||
167 | - + finalArr[7].name + ' : ' + String(finalArr[7].pumpingRatio) + '\n' | ||
168 | - + finalArr[8].name + ' : ' + String(finalArr[8].pumpingRatio) + '\n' | ||
169 | - + finalArr[9].name + ' : ' + String(finalArr[9].pumpingRatio) + '\n' | ||
170 | - } | ||
171 | - ] | ||
172 | - } | ||
173 | - },(error, response, body) => { | ||
174 | - console.log(body) | ||
175 | - }); | ||
176 | - res.sendStatus(200); | ||
177 | - | ||
178 | - }) | ||
179 | - }) | ||
180 | - }) | ||
181 | - }) | ||
182 | - }) | ||
183 | -} | ||
184 | - | ||
185 | -try { | ||
186 | - const option = { | ||
187 | - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ||
188 | - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
189 | - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
190 | - }; | ||
191 | - | ||
192 | - HTTPS.createServer(option, app).listen(sslport, () => { | ||
193 | - console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
194 | - }); | ||
195 | - } catch (error) { | ||
196 | - console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
197 | - console.log(error); | ||
198 | - } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment