정홍주

코인 시세 받아오기

node_modules/
\ No newline at end of file
var express = require('express');
var app = express();
var fs = require('fs');
const fetch = require('node-fetch');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/price', function(req, res) {
var arr ;
var responseList = new Array();
fs.readFile('coin_name.txt', 'utf8', function(err,data){
arr = data.split(",");
console.log(arr);
for(var i=0;i<1;i++){
const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
var coinJson = new Object();
fetch(url, options)
.then(req => req.json())
.then(json => {
coinJson.coin = arr[i];
coinJson.price = json[0]["trade_price"];
responseList.push(coinJson);
})
.catch(err => console.error('error:' + err));
}
}).then(function(){
jsonData = JSON.stringify(responseList);
res.send(jsonData);
});
})
var server = app.listen(8082);
console.log("Server Created..");
\ No newline at end of file
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>hello</h1>
</body>
</html>
\ No newline at end of file
const fetch = require('node-fetch');
const url = 'https://api.upbit.com/v1/candles/minutes/1?market=KRW-XRP&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json[0].trade_price))
.catch(err => console.error('error:' + err));
\ No newline at end of file
const fetch = require('node-fetch');
const fs = require('fs');
const url = 'https://api.upbit.com/v1/market/all?isDetails=false';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
fetch(url, options)
.then(res => res.json())
.then(json => {
var coinName = [];
var j = 0;
var file = 'coin_name.txt';
fs.open(file,'w',function(err,fd){
if(err) throw err;
});
for (i=0;i<json.length;i++) {
if (json[i].market.indexOf("KRW")>-1){
console.log(json[i].market);
coinName[j] = json[i].market;
j=j+1;
}
}
console.log(coinName);
fs.writeFile(file,coinName,'utf8',function(error){
console.log('write end')
});
})
.catch(err => console.error('error:' + err));
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"name": "Coin-trade-assistant",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "http://khuhub.khu.ac.kr/2018102235/Coin-trade-assistant.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"node-fetch": "^2.6.1",
"request": "^2.88.2"
}
}
const fetch = require('node-fetch');
var fs = require('fs');
var responseList = new Array();
fs.readFile('coin_name.txt', 'utf8', function(err,data){
arr = data.split(",");
// console.log(arr);
for(var i=0;i<10;i++){
(function(i){
setTimeout(function(){
const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
var coinJson = new Object();
fetch(url, options)
.then(res => res.json())
.then(json => {
coinJson.coin = arr[i];
coinJson.price = json[0].trade_price;
})
.then(function(){
responseList.push(coinJson);
console.log(responseList);
})
.catch(err => console.error('error:' + err));
},10);
})(i);
}
})
for(var i =0; i<10;i++){
(function(i){
setTimeout(function(){
console.log(i);
},10);
})(i);
}
\ No newline at end of file