정홍주

Merge master Whale

node_modules/
apiKey.json
\ No newline at end of file
apiKey.json
apiKeyWhale
app_chatbot.js
app_whale.js
\ No newline at end of file
......
var express = require('express');
const Token = require('./apiKey.json');
const request = require('request');const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const request = require('request');
const TARGET_URL_PUSH = 'https://api.line.me/v2/bot/message/push'
const TARGET_URL_REPLY = 'https://api.line.me/v2/bot/message/reply'
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
const USER_ID = 'U15e01e0a7f2c980b8cb755421312fba4'
const TOKEN = Token.line_token;
const binanceKey = Token.binance_key;
const fs = require('fs');
......@@ -11,9 +16,25 @@ const rp = require('request-promise');
const domain = "2018102235.oss2021.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
const fs_apikey = require('fs');
const api_key = fs_apikey.readFileSync('apiKeyWhale', 'ascii')
var app = express();
var command = '';
var cursor = ''
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
var TimeNow = parseInt((new Date()).getTime() / 1000)
var uts2time = new Date()
var PushTimeId;
console.log(TimeNow)
var explain = 0;
app.use(bodyParser.json());
if(explain <1){
explain_message();
}
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
......@@ -24,13 +45,20 @@ app.post('/hook', function (req, res) {
console.log('[request]', req.body);
console.log('[request source] ', source);
console.log('[request message]', message);
if(message.text === '김프'){
command = '김프';
}
else if (message.text === '거래량비율')
else if (message.text === '거래량비율'){
volumePumpingRatioThreeMinutePerWeek(eventObj.replyToken, message.text);
}
else if(message.text == '고래알람'){
PushTimeId = SetWhaleAlert()
}
else if(message.text == '고래알람해제'){
clearTimeout(PushTimeId)
}
else{
if(command === '김프'){
kimp(eventObj.replyToken, message.text);
......@@ -39,7 +67,42 @@ app.post('/hook', function (req, res) {
res.sendStatus(200);
});
function explain_message(){
request.post(
{
url: TARGET_URL_PUSH,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"messages":[
{
"type":"text",
"text":"코인거래를 도와주는 챗봇입니다."
},
{
"type":"text",
"text":"명령어 : 김프, 거래량비율, 고래알람, 고래알람해제"
},
{
"type":"text",
"text":"김프 입력 후 BTC, ETH 등 코인 심볼을 입력하면 국내와 해외 시세 차이를 알 수 있습니다."
},
{
"type":"text",
"text":"거래량비율 입력을 하면 30~1분 후 최근 거래량이 활발한 10개 상위 종목을 알 수 있습니다."
},
{
"type":"text",
"text":"고래알람 입력을 하면 실시간으로 고래들이 입금한 코인과 액수를 알 수 있습니다. 급등 급락할 확률이 높다는 것을 의미합니다."
}
]
}
},(error, response, body) => {
console.log(body, error)
});
}
function kimp(replyToken,message){
var upbitPrice = 0;
......@@ -101,7 +164,7 @@ function compare_price(replyToken, message, upbitPrice){
binance_price().then(function(binancePrice){
request.post(
{
url: TARGET_URL,
url: TARGET_URL_REPLY,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
......@@ -242,7 +305,7 @@ function volumePumpingRatioThreeMinutePerWeek(replyToken, message)
console.log(finalArr);
request.post(
{
url: TARGET_URL,
url: TARGET_URL_REPLY,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
......@@ -275,7 +338,102 @@ function volumePumpingRatioThreeMinutePerWeek(replyToken, message)
})
})
}
function chk_param(data, query_limit, callback){
//query_limit (non_int) => return 0;
//query_limit (int) => return query_limit;
query_limit = parseInt(query_limit)
if(isNaN(query_limit)){ return callback(data, 0)}
else {return callback(data, query_limit)}
}
function data_collector(data, limit){
var ret = new Array();
var str = '';
//ret += '# of Transactions : ' + data.count + '\n'
for(var i = 0; i < data.count; i++){
uts2time.setTime(data.transactions[i].timestamp * 1000 + KR_TIME_DIFF)
str = /*'#' + (i+1)+*/'Time: ' + uts2time.toLocaleString() + '\nChainName: '+data.transactions[i].blockchain+'\nAmount: '+data.transactions[i].amount+' USD'
if(data.transactions[i].amount > limit){
//console.log(str)
// ret += '\n\n' + str;
o ={ 'type' : 'text',
'text' : str}
ret.push(o)
}
else{
//console.log(str)
}
}
return ret;
}
function SetWhaleAlert(){
url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&cursor=' + cursor;
const options = {method: 'GET', headers: {Accept: 'application/json'}};
fetch(url2, options)
.then(res => res.json())
.then(json => {
console.log(json)
fetch(url2+json.cursor, options)
.then(res => res.json())
.then(json => {
console.log(json)
fetch(url2+json.cursor, options)
.then(res => res.json())
.then(json => {
console.log(json)
if(json.cursor != undefined){
cursor = json.cursor
}
})
.catch((err) => {
console.log('error : inital_fetch:'+err)
})
})
.catch((err) => {
console.log('error : inital_fetch:'+err)
})
})
.catch((err) => {
console.log('error : inital_fetch:'+err)
})
return setInterval(() => {
fetch(url2+cursor, options)
.then(res => res.json())
.then(json => {
//API usage limit
console.log(json)
if(json.result == 'error'){
}
else{
cursor = json.cursor
var msg2user = chk_param(json,5000000, data_collector)
console.log('msg',msg2user)
if(msg2user.length){
var i = 0;
for(i; i < msg2user.length; i++){
request.post(
{
url: TARGET_URL_PUSH,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"messages":[msg2user[i]]
}
},(error, response, body) => {
console.log(body, error)
});
}
}
}
})
.catch(err => {
console.error('error: var:fu:' + err)
})
}, 5000);
}
try {
const option = {
......
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,KR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