배지승

최솟값 parameter 추가

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