정홍주

코인 시세 받아오기

1 +node_modules/
...\ No newline at end of file ...\ No newline at end of file
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
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
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +<head>
4 + <meta charset="UTF-8">
5 + <title>Document</title>
6 +</head>
7 +<body>
8 + <h1>hello</h1>
9 +</body>
10 +</html>
...\ No newline at end of file ...\ No newline at end of file
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
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
This diff is collapsed. Click to expand it.
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 +}
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 +})
1 +for(var i =0; i<10;i++){
2 + (function(i){
3 + setTimeout(function(){
4 + console.log(i);
5 + },10);
6 + })(i);
7 +}
...\ No newline at end of file ...\ No newline at end of file