app.js
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require('express');
const app = express();
const fetch = require('node-fetch');
const fs = require('fs')
const api_key = fs.readFileSync('apikey', 'ascii')
console.log('apikey:',api_key)
//const url = 'https://api.whale-alert.io/v1/status?api_key=' + api_key;
const options = {method: 'GET', headers: {Accept: 'application/json'}};
cursor = ''
const url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key;
// fetch(url, options)
// .then(res => res.json())
// .then(json => console.log(json))
// .catch(err => console.error('error:' + err));
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 = '';
var str = '';
for(var i = 0; i < data.transactions.length; i++){
str = '#' + (i+1)+' ChainName: '+data.transactions[i].blockchain+'\tAmount: '+data.transactions[i].amount+' USD'
if(data.transactions[i].amount > limit){
//console.log(str)
ret += '</br>' + str;
}
else{
//console.log(str)
}
}
return ret;
}
app.get('/', function (req, res) {
fu = fetch(url2, options);
fu.then(res => res.json())
.then(json => {
//API usage limit
console.log(json)
if(json.result == 'error'){
res.send("Please try later")
}
else{
res.send(chk_param(json, req.query.limit, data_collector))
}
})
.catch(err => console.error('error:' + err))
})
var server = app.listen(23023)