Showing
2 changed files
with
77 additions
and
53 deletions
| ... | @@ -15,6 +15,7 @@ const connect = mongoose.connect(config.mongoURI, { | ... | @@ -15,6 +15,7 @@ const connect = mongoose.connect(config.mongoURI, { |
| 15 | .then(() => console.log('디비연결 성공')) | 15 | .then(() => console.log('디비연결 성공')) |
| 16 | .catch((err) => console.log(err)); | 16 | .catch((err) => console.log(err)); |
| 17 | 17 | ||
| 18 | +var korean_name = new Object(); | ||
| 18 | 19 | ||
| 19 | async function get_marketName() { | 20 | async function get_marketName() { |
| 20 | var data = new Array(); | 21 | var data = new Array(); |
| ... | @@ -24,6 +25,7 @@ async function get_marketName() { | ... | @@ -24,6 +25,7 @@ async function get_marketName() { |
| 24 | .then(json => { | 25 | .then(json => { |
| 25 | for (i in json) { | 26 | for (i in json) { |
| 26 | data.push(json[i].market); | 27 | data.push(json[i].market); |
| 28 | + korean_name[json[i].market] = json[i].korean_name; | ||
| 27 | } | 29 | } |
| 28 | }) | 30 | }) |
| 29 | return data; | 31 | return data; |
| ... | @@ -57,6 +59,7 @@ async function save_coin(arr) { | ... | @@ -57,6 +59,7 @@ async function save_coin(arr) { |
| 57 | const coin = new Coin({ | 59 | const coin = new Coin({ |
| 58 | tid: i + 1, | 60 | tid: i + 1, |
| 59 | name: arr[i][0], | 61 | name: arr[i][0], |
| 62 | + korean_name: korean_name[arr[i][0]], | ||
| 60 | acc_trade_price_24h: arr[i][1], | 63 | acc_trade_price_24h: arr[i][1], |
| 61 | current_price: arr[i][2] | 64 | current_price: arr[i][2] |
| 62 | }); | 65 | }); |
| ... | @@ -69,35 +72,6 @@ async function save_coin(arr) { | ... | @@ -69,35 +72,6 @@ async function save_coin(arr) { |
| 69 | } | 72 | } |
| 70 | return true; | 73 | return true; |
| 71 | } | 74 | } |
| 72 | -async function get_candle(minute, market) { | ||
| 73 | - const url = `https://api.upbit.com/v1/candles/minutes/${minute}?market=${market}&count=1`; | ||
| 74 | - var candle = new Array(); | ||
| 75 | - let response = await fetch(url, options) | ||
| 76 | - .then(res => res.json()) | ||
| 77 | - .then(json => candle = json) | ||
| 78 | - return candle; | ||
| 79 | -} | ||
| 80 | -app.get('/get_market', async (req, res) => { | ||
| 81 | - var name_list = (await get_marketName()); | ||
| 82 | - var market_info = (await get_marketInfo(name_list)); | ||
| 83 | - sort_info = (await sort_data(market_info)); | ||
| 84 | - res.json(await save_coin(sort_info)); | ||
| 85 | - | ||
| 86 | -}) | ||
| 87 | -app.get('/get_candle', async (req, res) => { | ||
| 88 | - Coin.find() | ||
| 89 | - .then(result => { | ||
| 90 | - result.forEach((item) => { | ||
| 91 | - get_candle(5, item.name) | ||
| 92 | - .then(result => { | ||
| 93 | - Coin.findOneAndUpdate({ name: result[0].market }, { five_candle: result[0].trade_price }, { new: true }, (err, doc) => { | ||
| 94 | - // console.log(doc); | ||
| 95 | - }) | ||
| 96 | - }) | ||
| 97 | - }) | ||
| 98 | - }); | ||
| 99 | - | ||
| 100 | -}) | ||
| 101 | async function refresh_db() { | 75 | async function refresh_db() { |
| 102 | Coin.find() | 76 | Coin.find() |
| 103 | .then(result => { | 77 | .then(result => { |
| ... | @@ -113,51 +87,100 @@ async function refresh_db() { | ... | @@ -113,51 +87,100 @@ async function refresh_db() { |
| 113 | save_coin(sort_info); | 87 | save_coin(sort_info); |
| 114 | }) | 88 | }) |
| 115 | } | 89 | } |
| 116 | -async function repeat_check(t1) { | 90 | +async function get_candle(minute, market) { |
| 117 | - await Coin.find().then(result => { | 91 | + const url = `https://api.upbit.com/v1/candles/minutes/${minute}?market=${market}&count=1`; |
| 118 | - for (var key in result) { | 92 | + var candle = new Array(); |
| 119 | - t1.push(result[key].name) | 93 | + let response = await fetch(url, options) |
| 120 | - } | 94 | + .then(res => res.json()) |
| 121 | - }) | 95 | + .then(json => candle = json) |
| 122 | - setTimeout(() => { | 96 | + return candle; |
| 123 | - setInterval(async () => { | 97 | +} |
| 98 | +async function check_coin(t1) { | ||
| 124 | for (var i = 0; i < t1.length; i++) { | 99 | for (var i = 0; i < t1.length; i++) { |
| 125 | - // console.log(t1.length); | ||
| 126 | - // console.log(t1[i]); | ||
| 127 | var candle = await get_candle(5, t1[i]); | 100 | var candle = await get_candle(5, t1[i]); |
| 128 | - // console.log(i+"번째 코인 가격 "+candle[0].trade_price); | ||
| 129 | await Coin.findOne({ name: candle[0].market }).then((result) => { | 101 | await Coin.findOne({ name: candle[0].market }).then((result) => { |
| 130 | - | ||
| 131 | //가격이 떨어졌을때 | 102 | //가격이 떨어졌을때 |
| 132 | if (result.current_price > candle[0].trade_price) { | 103 | if (result.current_price > candle[0].trade_price) { |
| 133 | - Coin.updateOne({ name: candle[0].market }, { current_price: candle[0].trade_price, $inc: { count: 1 } }, (err, result) => { | 104 | + Coin.findOneAndUpdate({ name: candle[0].market }, { current_price: candle[0].trade_price, $inc: { count: 1 } }, { new: true }, (err, result) => { |
| 134 | if (err) { | 105 | if (err) { |
| 135 | console.log(err); | 106 | console.log(err); |
| 136 | } else { | 107 | } else { |
| 108 | + console.log("***" + result.korean_name + "은(는)" + result.count * 5 + "분 동안 하락중"); | ||
| 137 | } | 109 | } |
| 138 | }) | 110 | }) |
| 139 | }//그대로 이거나 올랐을때 | 111 | }//그대로 이거나 올랐을때 |
| 140 | else { | 112 | else { |
| 141 | - Coin.updateOne({ name: candle[0].market }, { current_price: candle[0].trade_price, count: 0 }, (err, result) => { | 113 | + Coin.findOneAndUpdate({ name: candle[0].market }, { current_price: candle[0].trade_price, count: 0 }, { new: true }, (err, result) => { |
| 142 | if (err) { | 114 | if (err) { |
| 143 | console.log(err); | 115 | console.log(err); |
| 144 | } else { | 116 | } else { |
| 117 | + console.log(result.korean_name + "은(는)" + result.count * 5 + "분 동안 상승 혹은 정체중"); | ||
| 145 | } | 118 | } |
| 146 | }) | 119 | }) |
| 147 | 120 | ||
| 148 | } | 121 | } |
| 149 | }) | 122 | }) |
| 150 | } | 123 | } |
| 151 | - }, 600 * 5); | ||
| 152 | - }, 600 * 5); | ||
| 153 | } | 124 | } |
| 154 | -app.listen(5000, async () => { | 125 | +// async function repeat_check(t1) { |
| 155 | - console.log('server start') | 126 | +// await Coin.find().sort({ tid: 1 }).then(result => { |
| 156 | - //coin 이름,가격,거래대금 저장 | 127 | +// for (var key in result) { |
| 128 | +// t1.push(result[key].name) | ||
| 129 | +// } | ||
| 130 | +// }) | ||
| 131 | +// let check_time = setInterval(() => { | ||
| 132 | +// let today = new Date(); | ||
| 133 | +// let minutes = today.getMinutes(); | ||
| 134 | +// let seconds = today.getSeconds(); | ||
| 135 | +// if (minutes % 5 == 0 && seconds == 0) { | ||
| 136 | +// clearInterval(check_time); | ||
| 137 | +// console.log("현재 시간은 " + today.toLocaleTimeString()); | ||
| 138 | +// check_coin(t1); | ||
| 139 | +// setInterval(async () => { | ||
| 140 | +// let today = new Date(); | ||
| 141 | +// console.log("현재 시간은 " + today.toLocaleTimeString()); | ||
| 142 | +// check_coin(t1); | ||
| 143 | +// }, 60000 * 5); | ||
| 144 | +// } | ||
| 145 | +// }, 1000) | ||
| 146 | + | ||
| 147 | +// } | ||
| 148 | +async function latest_repeat(t1) { | ||
| 149 | + await Coin.find().sort({ tid: 1 }).then(result => { | ||
| 150 | + for (var key in result) { | ||
| 151 | + t1.push(result[key].name) | ||
| 152 | + } | ||
| 153 | + }) | ||
| 154 | + let check_time = setInterval(async () => { | ||
| 155 | + let today = new Date(); | ||
| 156 | + let minutes = today.getMinutes(); | ||
| 157 | + let seconds = today.getSeconds(); | ||
| 158 | + if (seconds == 0) { | ||
| 159 | + // if (minutes == 0 && seconds == 0) { | ||
| 160 | + clearInterval(check_time); | ||
| 161 | + sort_info = (await sort_data()); | ||
| 162 | + (await refresh_db()); | ||
| 163 | + console.log("현재 시간은 " + today.toLocaleTimeString()); | ||
| 164 | + let coin=setInterval(async () => { | ||
| 165 | + let today = new Date(); | ||
| 166 | + let minutes=today.getMinutes(); | ||
| 167 | + let seconds=today.getSeconds(); | ||
| 168 | + console.log("현재 시간은 " + today.toLocaleTimeString()); | ||
| 169 | + await (check_coin(t1)); | ||
| 170 | + if(minutes==0&&seconds==0){ | ||
| 157 | sort_info = (await sort_data()); | 171 | sort_info = (await sort_data()); |
| 158 | - //DB 최신화 | ||
| 159 | (await refresh_db()); | 172 | (await refresh_db()); |
| 173 | + console.log("db 최신화"); | ||
| 174 | + } | ||
| 175 | + }, 60000*5); | ||
| 176 | + } | ||
| 177 | + }, 1000); | ||
| 178 | +} | ||
| 179 | +app.listen(5000, async () => { | ||
| 180 | + console.log('server start') | ||
| 181 | + //coin 이름,가격,거래대금 저장 , DB 최신화 1시간마다 반복 | ||
| 182 | + //5분마다 현재 가격 가져와서 db랑 비교후 매수 매도 기준잡기 | ||
| 160 | var t1 = new Array(); | 183 | var t1 = new Array(); |
| 161 | - test_data = await (repeat_check(t1)); | 184 | + test_data=await (latest_repeat(t1)); |
| 162 | //반복 | 185 | //반복 |
| 163 | }) | 186 | }) |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -8,6 +8,10 @@ const coinSchema=mongoose.Schema({ | ... | @@ -8,6 +8,10 @@ const coinSchema=mongoose.Schema({ |
| 8 | type:String, | 8 | type:String, |
| 9 | required:true | 9 | required:true |
| 10 | }, | 10 | }, |
| 11 | + korean_name:{ | ||
| 12 | + type:String, | ||
| 13 | + required:true | ||
| 14 | + }, | ||
| 11 | acc_trade_price_24h:{ | 15 | acc_trade_price_24h:{ |
| 12 | type:Number, | 16 | type:Number, |
| 13 | required:true | 17 | required:true |
| ... | @@ -16,9 +20,6 @@ const coinSchema=mongoose.Schema({ | ... | @@ -16,9 +20,6 @@ const coinSchema=mongoose.Schema({ |
| 16 | type:Number, | 20 | type:Number, |
| 17 | required:true | 21 | required:true |
| 18 | }, | 22 | }, |
| 19 | - five_candle:{ | ||
| 20 | - type:Number | ||
| 21 | - }, | ||
| 22 | count:{ | 23 | count:{ |
| 23 | type:Number, | 24 | type:Number, |
| 24 | default:0 | 25 | default:0 | ... | ... |
-
Please register or login to post a comment