전현진

Delete duplicate, unnecessary files

node_modules/
\ No newline at end of file
File mode changed
......@@ -6,45 +6,108 @@ var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/price', function(req, res) {
app.get('/pumping', function(req, res) {
fs.readFile('coin_name.txt', 'utf8', function(err,data){
arr = data.split(",");
// console.log(arr);
var responseList = new Array();
function print_coin(){
var promise = new Promise(function(resolve,reject){
for(j=0;j<arr.length/10;j++){
for(i=j*10;i<(j+1)*10;i++){
(function(i){
setTimeout(function(){
const url = 'https://api.upbit.com/v1/candles/minutes/1?market='+arr[i]+'&count=1';
coinNameArr = data.split(",");
var volumePerWeekArr = new Array();
function getWeekVolume()
{
var promise = new Promise(function(resolve, reject)
{
for (i = 0; i < coinNameArr.length; ++i)
{
(function (i)
{
setTimeout(function () {
const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[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 = coinNameArr[i];
coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume;
volumePerWeekArr.push(coinJson);
if (volumePerWeekArr.length >= coinNameArr.length)
resolve(volumePerWeekArr);
})
.catch(err => console.error('error:' + err));
}, i*300);
})(i);
}
});
return promise;
}
var volumePerThreeMinArr = new Array();
function getThreeMinVolume()
{
var promise = new Promise(function(resolve, reject)
{
for (i = 0; i < coinNameArr.length; ++i)
{
(function (i)
{
setTimeout(function () {
const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[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;
responseList.push(coinJson);
console.log(i)
if(i>115){
resolve(responseList);
}
coinJson.coin = coinNameArr[i];
coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume;
volumePerThreeMinArr.push(coinJson);
if (volumePerThreeMinArr.length >= coinNameArr.length)
resolve(volumePerThreeMinArr);
})
.catch(err => console.error('error:' + err));
},i*180);
})(i);
}
}, i*300);
})(i);
}
});
return promise;
}
print_coin().then(function(resList){
res.send(resList);
});
})
}
var pumpingArr = new Array();
function getResultArr(volArr, minArr)
{
var promise = new Promise(function(resolve, reject)
{
for (var i = 0; i < coinNameArr.length; i++)
{
var coinJson = new Object();
coinJson.name = coinNameArr[i];
coinJson.pumpingRatio = minArr[i].tradeVolumePerThreeMin / volArr[i].tradeVolumePerWeek * 1000000
pumpingArr.push(coinJson);
console.log(coinJson);
if (pumpingArr.length >= coinNameArr.length)
resolve(pumpingArr);
}
})
return promise;
}
// get
getWeekVolume().then(function(volArr){
getThreeMinVolume().then(function(minArr){
getResultArr(volArr, minArr).then(function(result){
res.send(result);
})
})
})
})
})
var server = app.listen(8082);
console.log("Server Created..");
console.log("Server Created..");
\ 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/weeks/?market=KRW-BTC&count=1';
// const options = {method: 'GET', headers: {Accept: 'application/json'}};
// fetch(url, options)
// .then(res => res.json())
// .then(json => console.log(json))
// .catch(err => console.error('error:' + err));
// const url = 'https://api.upbit.com/v1/candles/weeks/?market=' + data + '&count=1';
// var pumpingArr = new Array();
// const options = {method: 'GET', headers: {Accept: 'application/json'}};
// var coinJson = new Object();
// fetch(url, options)
// .then(res => res.json())
// .then(json => {
// coinJson.coin = 'KRW-BTC';
// coinJson.tradeVolume = json[0].candle_acc_trade_volume;
// console.log(coinJson);
// pumpingArr.push(coinJson);
// console.log(pumpingArr);
// })
// .catch(err => console.error('error:' + err));
const fetch = require('node-fetch');
const url = 'https://api.upbit.com/v1/candles/minutes/1?market=KRW-XRP&count=1';
const url = 'https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&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
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
......
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
{
"name": "Coin-trade-assistant",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"accepts": {
"version": "1.3.7",
......
{
"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"
}
}
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('/pumping', function(req, res) {
fs.readFile('coin_name.txt', 'utf8', function(err,data){
coinNameArr = data.split(",");
var volumePerWeekArr = new Array();
function getWeekVolume()
{
var promise = new Promise(function(resolve, reject)
{
for (i = 0; i < coinNameArr.length; ++i)
{
(function (i)
{
setTimeout(function () {
const url = 'https://api.upbit.com/v1/candles/weeks/?market='+coinNameArr[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 = coinNameArr[i];
coinJson.tradeVolumePerWeek = json[0].candle_acc_trade_volume;
volumePerWeekArr.push(coinJson);
if (volumePerWeekArr.length >= coinNameArr.length)
resolve(volumePerWeekArr);
})
.catch(err => console.error('error:' + err));
}, i*300);
})(i);
}
});
return promise;
}
var volumePerThreeMinArr = new Array();
function getThreeMinVolume()
{
var promise = new Promise(function(resolve, reject)
{
for (i = 0; i < coinNameArr.length; ++i)
{
(function (i)
{
setTimeout(function () {
const url = 'https://api.upbit.com/v1/candles/minutes/3?market='+coinNameArr[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 = coinNameArr[i];
coinJson.tradeVolumePerThreeMin = json[0].candle_acc_trade_volume;
volumePerThreeMinArr.push(coinJson);
if (volumePerThreeMinArr.length >= coinNameArr.length)
resolve(volumePerThreeMinArr);
})
.catch(err => console.error('error:' + err));
}, i*300);
})(i);
}
});
return promise;
}
var pumpingArr = new Array();
function getResultArr(volArr, minArr)
{
var promise = new Promise(function(resolve, reject)
{
for (var i = 0; i < coinNameArr.length; i++)
{
var coinJson = new Object();
coinJson.name = coinNameArr[i];
coinJson.pumpingRatio = minArr[i].tradeVolumePerThreeMin / volArr[i].tradeVolumePerWeek * 1000000
pumpingArr.push(coinJson);
console.log(coinJson);
if (pumpingArr.length >= coinNameArr.length)
resolve(pumpingArr);
}
})
return promise;
}
// get
getWeekVolume().then(function(volArr){
getThreeMinVolume().then(function(minArr){
getResultArr(volArr, minArr).then(function(result){
res.send(result);
})
})
})
})
})
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
// const fetch = require('node-fetch');
// const url = 'https://api.upbit.com/v1/candles/weeks/?market=KRW-BTC&count=1';
// const options = {method: 'GET', headers: {Accept: 'application/json'}};
// fetch(url, options)
// .then(res => res.json())
// .then(json => console.log(json))
// .catch(err => console.error('error:' + err));
// const url = 'https://api.upbit.com/v1/candles/weeks/?market=' + data + '&count=1';
// var pumpingArr = new Array();
// const options = {method: 'GET', headers: {Accept: 'application/json'}};
// var coinJson = new Object();
// fetch(url, options)
// .then(res => res.json())
// .then(json => {
// coinJson.coin = 'KRW-BTC';
// coinJson.tradeVolume = json[0].candle_acc_trade_volume;
// console.log(coinJson);
// pumpingArr.push(coinJson);
// console.log(pumpingArr);
// })
// .catch(err => console.error('error:' + err));
const fetch = require('node-fetch');
const url = 'https://api.upbit.com/v1/candles/minutes/1?market=KRW-BTC&count=1';
const options = {method: 'GET', headers: {Accept: 'application/json'}};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
This diff is collapsed. Click to expand it.
const fetch = require('node-fetch');
var fs = require('fs');
fs.readFile('coin_name.txt', 'utf8', function(err,data){
arr = data.split(",");
// console.log(arr);
var responseList = new Array();
for(j=0;j<2;j++){
for(i=j*10;i<(j+1)*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;
responseList.push(coinJson);
// console.log(responseList)
console.log(i)
})
.catch(err => console.error('error:' + err));
},i*180);
})(i);
}
}
})
const delay = () => {
const randomDelay = Math.floor(Math.random() * 4) * 100
return new Promise(resolve => setTimeout(resolve, randomDelay))
}
const loop = async (list) => {
console.log("시작")
const promises = list.map(async data => {
return await delay()
.then(() => data)
})
const results = await Promise.all(promises)
results.forEach(data => console.log(data))
console.log("끝")
}
const list = [1, 2, 3, 4, 5, 6, 7]
loop(list)
\ No newline at end of file