전현진

add volumePerWeek, volumePerThreeMinute

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());
var pumpingArr = new Array();
var volumePerWeekArr = new Array();
var volumePerThreeMinArr = new Array();
function getWeekVolume()
{
fs.readFile('coin_name2.txt', 'utf8', function(err,data){
coinNameArr = data.split(",");
var promise = new Promise(function(resolve, reject)
{
for(j = 0; j < coinNameArr.length / 10; j++){
for(i = j * 10; i < (j + 1) * 10 && 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);
console.log(coinJson);
console.log(i)
if(volumePerWeekArr.length>coinNameArr.length){
resolve(volumePerWeekArr);
}
})
.catch(err => console.error('error:' + err));
},i*180);
})(i);
}
}
//if(volumePerWeekArr.length > coinNameArr.length){
// console.log(volumePerThreeMinArr.length)
// resolve(volumePerWeekArr);
//}
});
return promise;
})
}
function getThreeMinVolume()
{
fs.readFile('coin_name2.txt', 'utf8', function(err,data){
coinNameArr = data.split(",");
var promise = new Promise(function(resolve, reject)
{
for(j = 0; j < coinNameArr.length / 10; j++){
for(i = j * 10; i < (j + 1) * 10 && 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);
console.log(coinJson);
console.log(i)
})
.catch(err => console.error('error:' + err));
},i*180);
})(i);
}
}
if(volumePerThreeMinArr.length > coinNameArr.length){
console.log(volumePerThreeMinArr.length)
resolve(volumePerThreeMinArr);
}
});
return promise;
})
}
async function getPumpingRatioArr()
{
await getWeekVolume();
await getThreeMinVolume();
await function()
{
console.log("함수 들어옴");
console.log(volumePerWeekArr);
console.log(volumePerThreeMinArr);
}
}
app.get('/pumping', function(req, res) {
getPumpingRatioArr();
//getThreeMinVolume();
//getWeekVolume();
// fs.readFile('coin_name2.txt', 'utf8', function(err,data){
// coinNameArr = data.split(",");
// async function getPumingRatioArr()
// {
// getThreeMinVolume();
// getWeekVolume();
// await getThreeMinVolume().then(function(volumePerThreeMinArr){ });
// await getWeekVolume().then(function(volumePerWeekArr){ });
// var coinJson = new Object();
// for (var i = 0; i < coinNameArr.length; i++)
// {
// coinJson.name = coinNameArr[i];
// coinJson.pumpingRatio = volumePerThreeMinArr[i].tradeVolumePerThreeMin / volumePerWeekArr[i].tradeVolumePerWeek * 100
// pumpingArr.push(coinJson);
// console.log(coinJson);
// }
// }
// getPumingRatioArr().then(function(pumpingArr){
// res.send(pumpingArr);
// });
// })
})
var server = app.listen(8082);
console.log("Server Created..");
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.