June

Add repeat taker function

......@@ -28,8 +28,9 @@ async function get_marketName() {
})
return data;
}
async function get_marketInfo(name_list) {
async function get_marketInfo() {
//각 암호화폐 정보 조회
var name_list = await get_marketName();
const url2 = `https://api.upbit.com/v1/ticker/?markets=${name_list}`;
var arr = new Array();
let response2 = await fetch(url2, options)
......@@ -43,7 +44,8 @@ async function get_marketInfo(name_list) {
})
return arr
}
async function sort_data(arr) {
async function sort_data() {
arr = await get_marketInfo();
arr.sort((a, b) => {
return b[1] - a[1];
})
......@@ -75,7 +77,6 @@ async function get_candle(minute, market) {
.then(json => candle = json)
return candle;
}
app.get('/get_market', async (req, res) => {
var name_list = (await get_marketName());
var market_info = (await get_marketInfo(name_list));
......@@ -90,13 +91,73 @@ app.get('/get_candle', async (req, res) => {
get_candle(5, item.name)
.then(result => {
Coin.findOneAndUpdate({ name: result[0].market }, { five_candle: result[0].trade_price }, { new: true }, (err, doc) => {
console.log(doc);
// console.log(doc);
})
})
})
});
})
app.listen(5000, () => {
console.log('server')
async function refresh_db() {
Coin.find()
.then(result => {
if (result.length !== 0) {
Coin.deleteMany({ tid: { $gt: 0 } }, (err, result) => {
if (err) {
console.log(err);
} else {
console.log(result);
}
})
}
save_coin(sort_info);
})
}
async function repeat_check(t1) {
await Coin.find().then(result => {
for (var key in result) {
t1.push(result[key].name)
}
})
setTimeout(() => {
setInterval(async () => {
for (var i = 0; i < t1.length; i++) {
// console.log(t1.length);
// console.log(t1[i]);
var candle = await get_candle(5, t1[i]);
// console.log(i+"번째 코인 가격 "+candle[0].trade_price);
await Coin.findOne({ name: candle[0].market }).then((result) => {
//가격이 떨어졌을때
if (result.current_price > candle[0].trade_price) {
Coin.updateOne({ name: candle[0].market }, { current_price: candle[0].trade_price, $inc: { count: 1 } }, (err, result) => {
if (err) {
console.log(err);
} else {
}
})
}//그대로 이거나 올랐을때
else {
Coin.updateOne({ name: candle[0].market }, { current_price: candle[0].trade_price, count: 0 }, (err, result) => {
if (err) {
console.log(err);
} else {
}
})
}
})
}
}, 600 * 5);
}, 600 * 5);
}
app.listen(5000, async () => {
console.log('server start')
//coin 이름,가격,거래대금 저장
sort_info = (await sort_data());
//DB 최신화
(await refresh_db());
var t1 = new Array();
test_data = await (repeat_check(t1));
//반복
})
\ No newline at end of file
......
......@@ -18,6 +18,10 @@ const coinSchema=mongoose.Schema({
},
five_candle:{
type:Number
},
count:{
type:Number,
default:0
}
})
......