-
Notifications
You must be signed in to change notification settings - Fork 19
/
poloniex.gs
35 lines (31 loc) · 1.38 KB
/
poloniex.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
// Poloniex API Private Request in Google Apps Script (GAS).
// By Moosy Research, see more cryptosheets on: https://sites.google.com/view/moosyresearch
function POL_GetBalance() {
var POLrequest = {
'apikey' : '•••••••••',
'secret' : '•••••••••',
'uri' :'https://poloniex.com/tradingApi',
'version' : '',
'command' : '',
'method' :'POST',
'payload' : 'command=returnCompleteBalances&account=all'
};
var response = POL_PrivateRequest(POLrequest);
Logger.log( JSON.parse(UrlFetchApp.fetch(response.uri, response.params)) );
}
function POL_PrivateRequest(polrequest) {
function HMACSHA512HEX(s, secret) { return ToHex(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, s, secret)).toString(); }
function ToHex(s) { return s.map(function(byte) { return ('0' + (byte & 0xFF).toString(16)).slice(-2);}).join(''); }
var nonce = 1495932972127042 + new Date().getTime();
polrequest.payload = polrequest.payload + "&nonce="+nonce;
params = {
'method' : polrequest.method,
'muteHttpExceptions': true,
'headers': {
'key' : polrequest.apikey,
'sign' : HMACSHA512HEX( polrequest.payload, polrequest.apisecret)
},
"payload": polrequest.payload,
}
return { uri: polrequest.uri , params: params};
}