-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelium.gs
More file actions
69 lines (58 loc) · 2.82 KB
/
Helium.gs
File metadata and controls
69 lines (58 loc) · 2.82 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
64
65
66
67
68
69
/**
* @OnlyCurrentDoc
*/
/*====================================================================================================================================*
CryptoTools Google Sheet Feed by TedCryptoOrg
====================================================================================================================================
Version: 0.1.0
Project Page: https://github.com/TedCryptoOrg/CryptoTools
Copyright: (c) 2021 by TedCrypto
License: MIT License
------------------------------------------------------------------------------------------------------------------------------------
A library for importing ones balances, staking, rewards, lending & farming rates, dex volume & fees, uniswap new pairs into Google spreadsheets. Functions include:
GETHOTSPOTADDRESS Return hotspot address by its name
GETHOTSPOTREWARDS Return hotspot rewards
For bug reports see https://github.com/TedCryptoOrg/CryptoTools/issues
------------------------------------------------------------------------------------------------------------------------------------
Changelog:
0.1.0 Initial release
*====================================================================================================================================*/
/**
* Given hotspotname grab the hotspot address which can be used to identify
* the hotspot in the API
*/
async function GETHOTSPOTADDRESS(hotspotName) {
var hotspotName = hotspotName.toLowerCase().split(' ').join('-');
console.log(hotspotName);
var apiUrl = 'https://api.helium.io/v1/hotspots/name/' + hotspotName;
var res = await UrlFetchApp.fetch(apiUrl) ;
var content = res.getContentText();
var obj= JSON.parse(content);
console.log(obj)
return obj.data[0].address;
}
/**
* Given the hotspot address and a min time in a Google Date Time object
* (and optionally a max time) it will return the rewards based on those restrictions
*
* e.g.:
* Return the last 31 days rewards
* =GETHOTSPOTREWARDS(GETHOTSPOTADDRESS("your hotspot name", TODAY() - 31))
* Return november rewards
* =GETHOTSPOTREWARDS(GETHOTSPOTADDRESS("your hotspot name", "2021/11/01", "2021/11/30"))
*/
async function GETHOTSPOTREWARDS(address, min_time, max_time = null) {
min_time_formatted = Utilities.formatDate(min_time, "GMT+1", "YYYY-MM-dd")
console.log(min_time_formatted);
var apiUrl = 'https://api.helium.io/v1/hotspots/'+address+'/rewards/sum?min_time='+min_time_formatted;
if (max_time) {
max_time_formatted = Utilities.formatDate(max_time, "GMT+1", "YYYY-MM-dd")
apiUrl += '&max_time='+max_time_formatted;
}
console.log(apiUrl);
var res = await UrlFetchApp.fetch(apiUrl) ;
var content = res.getContentText();
var obj= JSON.parse(content);
console.log(obj, 'total', obj.data.total);
return obj.data.total;
}