Showing
10 changed files
with
152 additions
and
0 deletions
.gitignore
0 → 100644
1 | +node_modules/ | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app.js
0 → 100644
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 | +app.get('/price', function(req, res) { | ||
10 | + var arr ; | ||
11 | + var responseList = new Array(); | ||
12 | + fs.readFile('coin_name.txt', 'utf8', function(err,data){ | ||
13 | + arr = data.split(","); | ||
14 | + console.log(arr); | ||
15 | + for(var i=0;i<1;i++){ | ||
16 | + const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1'; | ||
17 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
18 | + | ||
19 | + var coinJson = new Object(); | ||
20 | + | ||
21 | + fetch(url, options) | ||
22 | + .then(req => req.json()) | ||
23 | + .then(json => { | ||
24 | + coinJson.coin = arr[i]; | ||
25 | + coinJson.price = json[0]["trade_price"]; | ||
26 | + responseList.push(coinJson); | ||
27 | + }) | ||
28 | + .catch(err => console.error('error:' + err)); | ||
29 | + | ||
30 | + } | ||
31 | + | ||
32 | + | ||
33 | + }).then(function(){ | ||
34 | + jsonData = JSON.stringify(responseList); | ||
35 | + res.send(jsonData); | ||
36 | + }); | ||
37 | +}) | ||
38 | +var server = app.listen(8082); | ||
39 | +console.log("Server Created.."); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
coin_name.txt
0 → 100644
1 | +KRW-BTC,KRW-ETH,KRW-NEO,KRW-MTL,KRW-LTC,KRW-XRP,KRW-ETC,KRW-OMG,KRW-SNT,KRW-WAVES,KRW-XEM,KRW-QTUM,KRW-LSK,KRW-STEEM,KRW-XLM,KRW-ARDR,KRW-KMD,KRW-ARK,KRW-STORJ,KRW-GRS,KRW-REP,KRW-EMC2,KRW-ADA,KRW-SBD,KRW-POWR,KRW-BTG,KRW-ICX,KRW-EOS,KRW-TRX,KRW-SC,KRW-IGNIS,KRW-ONT,KRW-ZIL,KRW-POLY,KRW-ZRX,KRW-LOOM,KRW-BCH,KRW-ADX,KRW-BAT,KRW-IOST,KRW-DMT,KRW-RFR,KRW-CVC,KRW-IQ,KRW-IOTA,KRW-MFT,KRW-ONG,KRW-GAS,KRW-UPP,KRW-ELF,KRW-KNC,KRW-BSV,KRW-THETA,KRW-EDR,KRW-QKC,KRW-BTT,KRW-MOC,KRW-ENJ,KRW-TFUEL,KRW-MANA,KRW-ANKR,KRW-AERGO,KRW-ATOM,KRW-TT,KRW-CRE,KRW-SOLVE,KRW-MBL,KRW-TSHP,KRW-WAXP,KRW-HBAR,KRW-MED,KRW-MLK,KRW-STPT,KRW-ORBS,KRW-VET,KRW-CHZ,KRW-PXL,KRW-STMX,KRW-DKA,KRW-HIVE,KRW-KAVA,KRW-AHT,KRW-LINK,KRW-XTZ,KRW-BORA,KRW-JST,KRW-CRO,KRW-TON,KRW-SXP,KRW-LAMB,KRW-HUNT,KRW-MARO,KRW-PLA,KRW-DOT,KRW-SRM,KRW-MVL,KRW-PCI,KRW-STRAX,KRW-AQT,KRW-BCHA,KRW-GLM,KRW-QTCON,KRW-SSX,KRW-META,KRW-OBSR,KRW-FCT2,KRW-LBC,KRW-CBK,KRW-SAND,KRW-HUM,KRW-DOGE,KRW-STRK,KRW-PUNDIX,KRW-FLOW,KRW-DAWN,KRW-AXS,KRW-STX | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
index.html
0 → 100644
index.js
0 → 100644
1 | +const fetch = require('node-fetch'); | ||
2 | + | ||
3 | +const url = 'https://api.upbit.com/v1/candles/minutes/1?market=KRW-XRP&count=1'; | ||
4 | +const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
5 | + | ||
6 | +fetch(url, options) | ||
7 | + .then(res => res.json()) | ||
8 | + .then(json => console.log(json[0].trade_price)) | ||
9 | + .catch(err => console.error('error:' + err)); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
market.js
0 → 100644
1 | +const fetch = require('node-fetch'); | ||
2 | +const fs = require('fs'); | ||
3 | +const url = 'https://api.upbit.com/v1/market/all?isDetails=false'; | ||
4 | +const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
5 | + | ||
6 | +fetch(url, options) | ||
7 | + .then(res => res.json()) | ||
8 | + .then(json => { | ||
9 | + var coinName = []; | ||
10 | + var j = 0; | ||
11 | + var file = 'coin_name.txt'; | ||
12 | + fs.open(file,'w',function(err,fd){ | ||
13 | + if(err) throw err; | ||
14 | + }); | ||
15 | + for (i=0;i<json.length;i++) { | ||
16 | + if (json[i].market.indexOf("KRW")>-1){ | ||
17 | + console.log(json[i].market); | ||
18 | + coinName[j] = json[i].market; | ||
19 | + j=j+1; | ||
20 | + } | ||
21 | + } | ||
22 | + console.log(coinName); | ||
23 | + fs.writeFile(file,coinName,'utf8',function(error){ | ||
24 | + console.log('write end') | ||
25 | + }); | ||
26 | + }) | ||
27 | + .catch(err => console.error('error:' + err)); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
package-lock.json
0 → 100644
This diff is collapsed. Click to expand it.
package.json
0 → 100644
1 | +{ | ||
2 | + "name": "Coin-trade-assistant", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "index.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1", | ||
8 | + "start": "node server.js" | ||
9 | + }, | ||
10 | + "repository": { | ||
11 | + "type": "git", | ||
12 | + "url": "http://khuhub.khu.ac.kr/2018102235/Coin-trade-assistant.git" | ||
13 | + }, | ||
14 | + "keywords": [], | ||
15 | + "author": "", | ||
16 | + "license": "ISC", | ||
17 | + "dependencies": { | ||
18 | + "body-parser": "^1.19.0", | ||
19 | + "express": "^4.17.1", | ||
20 | + "jsonwebtoken": "^8.5.1", | ||
21 | + "node-fetch": "^2.6.1", | ||
22 | + "request": "^2.88.2" | ||
23 | + } | ||
24 | +} |
test.js
0 → 100644
1 | +const fetch = require('node-fetch'); | ||
2 | +var fs = require('fs'); | ||
3 | + | ||
4 | +var responseList = new Array(); | ||
5 | +fs.readFile('coin_name.txt', 'utf8', function(err,data){ | ||
6 | + arr = data.split(","); | ||
7 | + | ||
8 | + // console.log(arr); | ||
9 | + | ||
10 | + for(var i=0;i<10;i++){ | ||
11 | + (function(i){ | ||
12 | + setTimeout(function(){ | ||
13 | + const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1'; | ||
14 | + const options = {method: 'GET', headers: {Accept: 'application/json'}}; | ||
15 | + | ||
16 | + var coinJson = new Object(); | ||
17 | + fetch(url, options) | ||
18 | + .then(res => res.json()) | ||
19 | + .then(json => { | ||
20 | + coinJson.coin = arr[i]; | ||
21 | + coinJson.price = json[0].trade_price; | ||
22 | + }) | ||
23 | + .then(function(){ | ||
24 | + responseList.push(coinJson); | ||
25 | + console.log(responseList); | ||
26 | + | ||
27 | + }) | ||
28 | + .catch(err => console.error('error:' + err)); | ||
29 | + },10); | ||
30 | + })(i); | ||
31 | + | ||
32 | + } | ||
33 | + | ||
34 | +}) |
-
Please register or login to post a comment