Showing
7 changed files
with
185 additions
and
4 deletions
... | @@ -27,12 +27,12 @@ app.get('/price', function(req, res) { | ... | @@ -27,12 +27,12 @@ app.get('/price', function(req, res) { |
27 | coinJson.price = json[0].trade_price; | 27 | coinJson.price = json[0].trade_price; |
28 | responseList.push(coinJson); | 28 | responseList.push(coinJson); |
29 | console.log(i) | 29 | console.log(i) |
30 | - if(i>115){ | 30 | + if(responseList.length>116){ |
31 | resolve(responseList); | 31 | resolve(responseList); |
32 | } | 32 | } |
33 | }) | 33 | }) |
34 | .catch(err => console.error('error:' + err)); | 34 | .catch(err => console.error('error:' + err)); |
35 | - },i*180); | 35 | + },i*110); |
36 | })(i); | 36 | })(i); |
37 | } | 37 | } |
38 | } | 38 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -16,9 +16,14 @@ | ... | @@ -16,9 +16,14 @@ |
16 | "license": "ISC", | 16 | "license": "ISC", |
17 | "dependencies": { | 17 | "dependencies": { |
18 | "body-parser": "^1.19.0", | 18 | "body-parser": "^1.19.0", |
19 | + "coingecko-api": "^1.0.10", | ||
20 | + "coinmarketcap-api": "^3.1.1", | ||
19 | "express": "^4.17.1", | 21 | "express": "^4.17.1", |
20 | "jsonwebtoken": "^8.5.1", | 22 | "jsonwebtoken": "^8.5.1", |
23 | + "node-binance-api": "^0.12.5", | ||
24 | + "node-coinmarketcap": "^0.2.0", | ||
21 | "node-fetch": "^2.6.1", | 25 | "node-fetch": "^2.6.1", |
22 | - "request": "^2.88.2" | 26 | + "request": "^2.88.2", |
27 | + "request-promise": "^4.2.6" | ||
23 | } | 28 | } |
24 | } | 29 | } | ... | ... |
... | @@ -24,7 +24,7 @@ fs.readFile('coin_name.txt', 'utf8', function(err,data){ | ... | @@ -24,7 +24,7 @@ fs.readFile('coin_name.txt', 'utf8', function(err,data){ |
24 | console.log(i) | 24 | console.log(i) |
25 | }) | 25 | }) |
26 | .catch(err => console.error('error:' + err)); | 26 | .catch(err => console.error('error:' + err)); |
27 | - },i*180); | 27 | + },i*10); |
28 | })(i); | 28 | })(i); |
29 | } | 29 | } |
30 | } | 30 | } | ... | ... |
... | @@ -17,3 +17,14 @@ console.log("끝") | ... | @@ -17,3 +17,14 @@ console.log("끝") |
17 | 17 | ||
18 | const list = [1, 2, 3, 4, 5, 6, 7] | 18 | const list = [1, 2, 3, 4, 5, 6, 7] |
19 | loop(list) | 19 | loop(list) |
20 | + | ||
21 | + | ||
22 | +// const result = async (list) => { | ||
23 | +// for (const data of list) { | ||
24 | +// await delay() | ||
25 | +// .then(() => console.log(data)) | ||
26 | +// } | ||
27 | +// } | ||
28 | + | ||
29 | +// const list = [1, 2, 3, 4, 5, 6, 7] | ||
30 | +// result(list) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
test3.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +const request = require('request'); | ||
3 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
4 | +const TOKEN = '6lwsXwectIjTZ1NWp6c1t5l8nXaOjWgfeYfTOWNRRTVftaXMb4eSMj2zeficMr4/FWtyPPBuUB120kxZp58bwDilssdU5Uhc4mWz4kCPfcgiEcVwzXUktbYRE3xKAJU1zdYAsZZvI+87KY8qZvaRngdB04t89/1O/w1cDnyilFU=' | ||
5 | +const fs = require('fs'); | ||
6 | +const path = require('path'); | ||
7 | +const HTTPS = require('https'); | ||
8 | +const domain = "2018102235.oss2021.tk" | ||
9 | +const sslport = 23023; | ||
10 | + | ||
11 | +const fetch = require('node-fetch'); | ||
12 | +const bodyParser = require('body-parser'); | ||
13 | +var app = express(); | ||
14 | +app.use(bodyParser.json()); | ||
15 | + | ||
16 | +app.post('/hook', function(req, res) { | ||
17 | + var eventObj = req.body.events[0]; | ||
18 | + var source = eventObj.source; | ||
19 | + var message = eventObj.message; | ||
20 | + // request log | ||
21 | + console.log('======================', new Date() ,'======================'); | ||
22 | + console.log('[request]', req.body); | ||
23 | + console.log('[request source] ', source); | ||
24 | + console.log('[request message]', message); | ||
25 | + | ||
26 | + fs.readFile('coin_name.txt', 'utf8', function(err,data){ | ||
27 | + arr = data.split(","); | ||
28 | + // console.log(arr); | ||
29 | + var responseList = new Array(); | ||
30 | + function print_coin(){ | ||
31 | + var promise = new Promise(function(resolve,reject){ | ||
32 | + for(j=0;j<arr.length/10;j++){ | ||
33 | + for(i=j*10;i<(j+1)*10;i++){ | ||
34 | + (function(i){ | ||
35 | + setTimeout(function(){ | ||
36 | + const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1'; | ||
37 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
38 | + var coinJson = new Object(); | ||
39 | + fetch(url, options) | ||
40 | + .then(res => res.json()) | ||
41 | + .then(json => { | ||
42 | + coinJson.coin = arr[i]; | ||
43 | + coinJson.price = json[0].trade_price; | ||
44 | + responseList.push(coinJson); | ||
45 | + console.log(i) | ||
46 | + if(responseList.length>116){ | ||
47 | + resolve(responseList); | ||
48 | + } | ||
49 | + }) | ||
50 | + .catch(err => console.error('error:' + err)); | ||
51 | + },i*110); | ||
52 | + })(i); | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + }); | ||
57 | + return promise; | ||
58 | + } | ||
59 | + | ||
60 | + request.post( | ||
61 | + { | ||
62 | + url: TARGET_URL, | ||
63 | + headers: { | ||
64 | + 'Authorization': `Bearer ${TOKEN}` | ||
65 | + }, | ||
66 | + json: { | ||
67 | + "replyToken":eventObj.replyToken, | ||
68 | + "messages":[ | ||
69 | + { | ||
70 | + "type":"text", | ||
71 | + "text":resList[0].coin | ||
72 | + } | ||
73 | + ] | ||
74 | + } | ||
75 | + },(error, response, body) => { | ||
76 | + console.log(body) | ||
77 | + }); | ||
78 | + res.sendStatus(200); | ||
79 | + }) | ||
80 | +}) | ||
81 | + | ||
82 | +app.post('/hook', function (req, res) { | ||
83 | + | ||
84 | + var eventObj = req.body.events[0]; | ||
85 | + var source = eventObj.source; | ||
86 | + var message = eventObj.message; | ||
87 | + // request log | ||
88 | + console.log('======================', new Date() ,'======================'); | ||
89 | + console.log('[request]', req.body); | ||
90 | + console.log('[request source] ', eventObj.source); | ||
91 | + console.log('[request message]', eventObj.message); | ||
92 | + | ||
93 | + | ||
94 | + request.post( | ||
95 | + { | ||
96 | + url: TARGET_URL, | ||
97 | + headers: { | ||
98 | + 'Authorization': `Bearer ${TOKEN}` | ||
99 | + }, | ||
100 | + json: { | ||
101 | + "replyToken":eventObj.replyToken, | ||
102 | + "messages":[ | ||
103 | + { | ||
104 | + "type":"text", | ||
105 | + "text":"Hello, user" | ||
106 | + }, | ||
107 | + { | ||
108 | + | ||
109 | + } | ||
110 | + ] | ||
111 | + } | ||
112 | + },(error, response, body) => { | ||
113 | + console.log(body) | ||
114 | + }); | ||
115 | + | ||
116 | + | ||
117 | + res.sendStatus(200); | ||
118 | +}); | ||
119 | + | ||
120 | +try { | ||
121 | + const option = { | ||
122 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ||
123 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
124 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
125 | + }; | ||
126 | + | ||
127 | + HTTPS.createServer(option, app).listen(sslport, () => { | ||
128 | + console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
129 | + }); | ||
130 | + } catch (error) { | ||
131 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
132 | + console.log(error); | ||
133 | + } | ||
134 | + |
test6.js
0 → 100644
1 | +const fetch = require('node-fetch'); | ||
2 | +const url = 'https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT'; | ||
3 | +const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
4 | +const rp = require('request-promise'); | ||
5 | +const requestOptions = { | ||
6 | + method: 'GET', | ||
7 | + uri: 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', | ||
8 | + qs: { | ||
9 | + 'start': '1', | ||
10 | + 'limit': '10', | ||
11 | + 'convert': 'KRW' | ||
12 | + }, | ||
13 | + headers: { | ||
14 | + 'X-CMC_PRO_API_KEY': 'c2f8e0b0-a253-4de3-a63f-9f564c8cdd1f' | ||
15 | + }, | ||
16 | + json: true, | ||
17 | + gzip: true | ||
18 | +}; | ||
19 | +fetch(url, options) | ||
20 | + .then(res => res.json()) | ||
21 | + .then(json => | ||
22 | + rp(requestOptions).then(response =>{ | ||
23 | + var i=0; | ||
24 | + while(response.data[i].id !== 825){ | ||
25 | + i = i+1; | ||
26 | + } | ||
27 | + console.log('API call response:', json.price*response.data[i].quote.KRW.price); | ||
28 | + }) | ||
29 | + | ||
30 | + ) | ||
31 | + .catch(err => console.error('error:' + err)); |
-
Please register or login to post a comment