배지승

거래 시간 표시 추가

1 const express = require('express'); 1 const express = require('express');
2 const app = express(); 2 const app = express();
3 -
4 -
5 -
6 const fetch = require('node-fetch'); 3 const fetch = require('node-fetch');
7 -const fs = require('fs'); 4 +const fs_apikey = require('fs');
8 - 5 +const api_key = fs_apikey.readFileSync('apikey', 'ascii')
9 -const api_key = fs.readFileSync('apikey', 'ascii')
10 -console.log('apikey:',api_key)
11 -//const url = 'https://api.whale-alert.io/v1/status?api_key=' + api_key
12 -const options = {method: 'GET', headers: {Accept: 'application/json'}};
13 -
14 var cursor = '' 6 var cursor = ''
15 -url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&limit=1&cursor=' + cursor; 7 +url2 = 'https://api.whale-alert.io/v1/transactions?api_key=' + api_key + '&cursor=' + cursor;
16 - 8 +const options = {method: 'GET', headers: {Accept: 'application/json'}};
17 -//Initialize timestamp
18 9
19 -const fs2 = require('fs') 10 +//Initialize cursor
20 -const fs3 = require('fs')
21 var TimeNow = parseInt((new Date()).getTime() / 1000) 11 var TimeNow = parseInt((new Date()).getTime() / 1000)
12 +var uts2time = new Date()
13 +
22 console.log(TimeNow) 14 console.log(TimeNow)
23 -console.log('파일쓰기')
24 fetch(url2, options) 15 fetch(url2, options)
25 .then(res => res.json()) 16 .then(res => res.json())
26 .then(json => { 17 .then(json => {
27 console.log(json) 18 console.log(json)
28 - fs2.writeFileSync('timestamp', json.cursor, 'ascii') 19 + cursor = json.cursor
20 +})
21 +.catch((err) => {
22 + console.log('error : inital_fetch:'+err)
29 }) 23 })
30 -// fetch(url, options)
31 -// .then(res => res.json())
32 -// .then(json => console.log(json))
33 -// .catch(err => console.error('error:' + err));
34 24
35 function chk_param(data, query_limit, callback){ 25 function chk_param(data, query_limit, callback){
36 //query_limit (non_int) => return 0; 26 //query_limit (non_int) => return 0;
...@@ -43,8 +33,10 @@ function data_collector(data, limit){ ...@@ -43,8 +33,10 @@ function data_collector(data, limit){
43 var ret = ''; 33 var ret = '';
44 var str = ''; 34 var str = '';
45 35
36 + ret += '# of Transactions : ' + data.count + '\n'
46 for(var i = 0; i < data.count; i++){ 37 for(var i = 0; i < data.count; i++){
47 - str = '#' + (i+1)+' ChainName: '+data.transactions[i].blockchain+'\tAmount: '+data.transactions[i].amount+' USD' 38 + uts2time.setTime(data.transactions[i].timestamp * 1000)
39 + str = '#' + (i+1)+' \tTime: ' + uts2time.toLocaleString() + '\tChainName: '+data.transactions[i].blockchain+'\tAmount: '+data.transactions[i].amount+' USD'
48 if(data.transactions[i].amount > limit){ 40 if(data.transactions[i].amount > limit){
49 //console.log(str) 41 //console.log(str)
50 ret += '</br>' + str; 42 ret += '</br>' + str;
...@@ -55,24 +47,24 @@ function data_collector(data, limit){ ...@@ -55,24 +47,24 @@ function data_collector(data, limit){
55 } 47 }
56 return ret; 48 return ret;
57 } 49 }
58 -app.get('/', function (req, res) { 50 +app.get('/whale', function (req, res) {
59 - cursor = fs3.readFileSync('timestamp', 'ascii') 51 + console.log('cursor', cursor)
60 - console.log('cursor', url2)
61 fu = fetch(url2+cursor, options); 52 fu = fetch(url2+cursor, options);
62 fu.then(res => res.json()) 53 fu.then(res => res.json())
63 .then(json => { 54 .then(json => {
64 //API usage limit 55 //API usage limit
65 console.log(json) 56 console.log(json)
66 -
67 if(json.result == 'error'){ 57 if(json.result == 'error'){
68 res.send("Please try later") 58 res.send("Please try later")
69 } 59 }
70 else{ 60 else{
71 - fs2.writeFileSync('timestamp', json.cursor, 'ascii') 61 + cursor = json.cursor
72 res.send(chk_param(json, req.query.limit, data_collector)) 62 res.send(chk_param(json, req.query.limit, data_collector))
73 } 63 }
74 }) 64 })
75 - .catch(err => console.error('error:' + err)) 65 + .catch(err => {
66 + console.error('error: var:fu:' + err)
67 + res.send('ERROR')
68 + })
76 }) 69 })
77 -
78 var server = app.listen(23023) 70 var server = app.listen(23023)
...\ No newline at end of file ...\ No newline at end of file
......
1 -6084feb2-6084feb2-60ba4692
...\ No newline at end of file ...\ No newline at end of file