-
Notifications
You must be signed in to change notification settings - Fork 19
/
delta_exchange.gs
41 lines (34 loc) · 1.79 KB
/
delta_exchange.gs
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
// Delta Exchange API Private Request in Google Apps Script (GAS).
// By Moosy Research, see more cryptosheets on: https://sites.google.com/view/moosyresearch
function DEL_GetBalances(){
var DELrequest = {
"id" : "DEL",
"name" : "DeltaExchange",
"apikey" : '•••••••••',
"secret" : '•••••••••',
"command" : "/v2/wallet/balances",
"uri" : "https://api.delta.exchange",
"method" : "GET",
"payload" : ""
}
var response = DEL_PrivateRequest(DELrequest);
Logger.log( JSON.parse(UrlFetchApp.fetch(response.uri, response.params)) );
}
function DEL_PrivateRequest(DELrequest) {
function HMACSHA256HEX(s, secret) { return ToHex(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, s, secret)).toString(); }
function ToHex(s) { return s.map(function(byte) { return ('0' + (byte & 0xFF).toString(16)).slice(-2);}).join(''); }
var timestamp = Math.floor(new Date().getTime() / 1000).toString().substring(0, 10),
signature_data = DELrequest.method + timestamp + DELrequest.command + '' + '',
params = {
method : DELrequest.method,
muteHttpExceptions : true,
headers : {
'api-key' : DELrequest.apikey,
'timestamp' : timestamp,
'signature' : HMACSHA256HEX(signature_data, DELrequest.secret),
'User-Agent' : 'rest-client',
'Content-Type' : 'application/json'
},
};
return { uri: DELrequest.uri + DELrequest.command , params: params};
}