정홍주

Merge master Whale

1 node_modules/ 1 node_modules/
2 apiKey.json 2 apiKey.json
3 +apiKeyWhale
4 +app_chatbot.js
5 +app_whale.js
...\ No newline at end of file ...\ No newline at end of file
......
1 var express = require('express'); 1 var express = require('express');
2 const Token = require('./apiKey.json'); 2 const Token = require('./apiKey.json');
3 -const request = require('request');const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 3 +const request = require('request');
4 +const TARGET_URL_PUSH = 'https://api.line.me/v2/bot/message/push'
5 +const TARGET_URL_REPLY = 'https://api.line.me/v2/bot/message/reply'
6 +const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
7 +const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
8 +const USER_ID = 'U15e01e0a7f2c980b8cb755421312fba4'
4 const TOKEN = Token.line_token; 9 const TOKEN = Token.line_token;
5 const binanceKey = Token.binance_key; 10 const binanceKey = Token.binance_key;
6 const fs = require('fs'); 11 const fs = require('fs');
...@@ -11,9 +16,25 @@ const rp = require('request-promise'); ...@@ -11,9 +16,25 @@ const rp = require('request-promise');
11 const domain = "2018102235.oss2021.tk" 16 const domain = "2018102235.oss2021.tk"
12 const sslport = 23023; 17 const sslport = 23023;
13 const bodyParser = require('body-parser'); 18 const bodyParser = require('body-parser');
19 +const fs_apikey = require('fs');
20 +const api_key = fs_apikey.readFileSync('apiKeyWhale', 'ascii')
14 var app = express(); 21 var app = express();
15 var command = ''; 22 var command = '';
23 +var cursor = ''
24 +
25 +
26 +const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
27 +var TimeNow = parseInt((new Date()).getTime() / 1000)
28 +var uts2time = new Date()
29 +
30 +var PushTimeId;
31 +console.log(TimeNow)
32 +var explain = 0;
33 +
16 app.use(bodyParser.json()); 34 app.use(bodyParser.json());
35 +if(explain <1){
36 + explain_message();
37 +}
17 app.post('/hook', function (req, res) { 38 app.post('/hook', function (req, res) {
18 39
19 var eventObj = req.body.events[0]; 40 var eventObj = req.body.events[0];
...@@ -27,10 +48,17 @@ app.post('/hook', function (req, res) { ...@@ -27,10 +48,17 @@ app.post('/hook', function (req, res) {
27 48
28 if(message.text === '김프'){ 49 if(message.text === '김프'){
29 command = '김프'; 50 command = '김프';
51 +
30 } 52 }
31 - else if (message.text === '거래량비율') 53 + else if (message.text === '거래량비율'){
32 volumePumpingRatioThreeMinutePerWeek(eventObj.replyToken, message.text); 54 volumePumpingRatioThreeMinutePerWeek(eventObj.replyToken, message.text);
33 - 55 + }
56 + else if(message.text == '고래알람'){
57 + PushTimeId = SetWhaleAlert()
58 + }
59 + else if(message.text == '고래알람해제'){
60 + clearTimeout(PushTimeId)
61 + }
34 else{ 62 else{
35 if(command === '김프'){ 63 if(command === '김프'){
36 kimp(eventObj.replyToken, message.text); 64 kimp(eventObj.replyToken, message.text);
...@@ -39,7 +67,42 @@ app.post('/hook', function (req, res) { ...@@ -39,7 +67,42 @@ app.post('/hook', function (req, res) {
39 67
40 res.sendStatus(200); 68 res.sendStatus(200);
41 }); 69 });
42 - 70 +function explain_message(){
71 + request.post(
72 + {
73 + url: TARGET_URL_PUSH,
74 + headers: {
75 + 'Authorization': `Bearer ${TOKEN}`
76 + },
77 + json: {
78 + "to": `${USER_ID}`,
79 + "messages":[
80 + {
81 + "type":"text",
82 + "text":"코인거래를 도와주는 챗봇입니다."
83 + },
84 + {
85 + "type":"text",
86 + "text":"명령어 : 김프, 거래량비율, 고래알람, 고래알람해제"
87 + },
88 + {
89 + "type":"text",
90 + "text":"김프 입력 후 BTC, ETH 등 코인 심볼을 입력하면 국내와 해외 시세 차이를 알 수 있습니다."
91 + },
92 + {
93 + "type":"text",
94 + "text":"거래량비율 입력을 하면 30~1분 후 최근 거래량이 활발한 10개 상위 종목을 알 수 있습니다."
95 + },
96 + {
97 + "type":"text",
98 + "text":"고래알람 입력을 하면 실시간으로 고래들이 입금한 코인과 액수를 알 수 있습니다. 급등 급락할 확률이 높다는 것을 의미합니다."
99 + }
100 + ]
101 + }
102 + },(error, response, body) => {
103 + console.log(body, error)
104 + });
105 +}
43 function kimp(replyToken,message){ 106 function kimp(replyToken,message){
44 107
45 var upbitPrice = 0; 108 var upbitPrice = 0;
...@@ -101,7 +164,7 @@ function compare_price(replyToken, message, upbitPrice){ ...@@ -101,7 +164,7 @@ function compare_price(replyToken, message, upbitPrice){
101 binance_price().then(function(binancePrice){ 164 binance_price().then(function(binancePrice){
102 request.post( 165 request.post(
103 { 166 {
104 - url: TARGET_URL, 167 + url: TARGET_URL_REPLY,
105 headers: { 168 headers: {
106 'Authorization': `Bearer ${TOKEN}` 169 'Authorization': `Bearer ${TOKEN}`
107 }, 170 },
...@@ -242,7 +305,7 @@ function volumePumpingRatioThreeMinutePerWeek(replyToken, message) ...@@ -242,7 +305,7 @@ function volumePumpingRatioThreeMinutePerWeek(replyToken, message)
242 console.log(finalArr); 305 console.log(finalArr);
243 request.post( 306 request.post(
244 { 307 {
245 - url: TARGET_URL, 308 + url: TARGET_URL_REPLY,
246 headers: { 309 headers: {
247 'Authorization': `Bearer ${TOKEN}` 310 'Authorization': `Bearer ${TOKEN}`
248 }, 311 },
...@@ -275,7 +338,102 @@ function volumePumpingRatioThreeMinutePerWeek(replyToken, message) ...@@ -275,7 +338,102 @@ function volumePumpingRatioThreeMinutePerWeek(replyToken, message)
275 }) 338 })
276 }) 339 })
277 } 340 }
341 +function chk_param(data, query_limit, callback){
342 + //query_limit (non_int) => return 0;
343 + //query_limit (int) => return query_limit;
344 + query_limit = parseInt(query_limit)
345 + if(isNaN(query_limit)){ return callback(data, 0)}
346 + else {return callback(data, query_limit)}
347 +}
348 +function data_collector(data, limit){
349 + var ret = new Array();
350 + var str = '';
278 351
352 + //ret += '# of Transactions : ' + data.count + '\n'
353 + for(var i = 0; i < data.count; i++){
354 + uts2time.setTime(data.transactions[i].timestamp * 1000 + KR_TIME_DIFF)
355 + str = /*'#' + (i+1)+*/'Time: ' + uts2time.toLocaleString() + '\nChainName: '+data.transactions[i].blockchain+'\nAmount: '+data.transactions[i].amount+' USD'
356 + if(data.transactions[i].amount > limit){
357 + //console.log(str)
358 + // ret += '\n\n' + str;
359 + o ={ 'type' : 'text',
360 + 'text' : str}
361 + ret.push(o)
362 + }
363 + else{
364 + //console.log(str)
365 + }
366 + }
367 + return ret;
368 +}
369 +function SetWhaleAlert(){
370 + url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&cursor=' + cursor;
371 + const options = {method: 'GET', headers: {Accept: 'application/json'}};
372 +
373 + fetch(url2, options)
374 + .then(res => res.json())
375 + .then(json => {
376 + console.log(json)
377 + fetch(url2+json.cursor, options)
378 + .then(res => res.json())
379 + .then(json => {
380 + console.log(json)
381 + fetch(url2+json.cursor, options)
382 + .then(res => res.json())
383 + .then(json => {
384 + console.log(json)
385 + if(json.cursor != undefined){
386 + cursor = json.cursor
387 + }
388 + })
389 + .catch((err) => {
390 + console.log('error : inital_fetch:'+err)
391 + })
392 + })
393 + .catch((err) => {
394 + console.log('error : inital_fetch:'+err)
395 + })
396 + })
397 + .catch((err) => {
398 + console.log('error : inital_fetch:'+err)
399 + })
400 + return setInterval(() => {
401 + fetch(url2+cursor, options)
402 + .then(res => res.json())
403 + .then(json => {
404 + //API usage limit
405 + console.log(json)
406 + if(json.result == 'error'){
407 + }
408 + else{
409 + cursor = json.cursor
410 + var msg2user = chk_param(json,5000000, data_collector)
411 + console.log('msg',msg2user)
412 + if(msg2user.length){
413 + var i = 0;
414 + for(i; i < msg2user.length; i++){
415 + request.post(
416 + {
417 + url: TARGET_URL_PUSH,
418 + headers: {
419 + 'Authorization': `Bearer ${TOKEN}`
420 + },
421 + json: {
422 + "to": `${USER_ID}`,
423 + "messages":[msg2user[i]]
424 + }
425 + },(error, response, body) => {
426 + console.log(body, error)
427 + });
428 + }
429 + }
430 + }
431 + })
432 + .catch(err => {
433 + console.error('error: var:fu:' + err)
434 + })
435 + }, 5000);
436 +}
279 437
280 try { 438 try {
281 const option = { 439 const option = {
......
1 -KRW-BTC,KRW-ETH,KRW-N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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
...\ No newline at end of file ...\ No newline at end of file
......