-
Notifications
You must be signed in to change notification settings - Fork 19
/
binance.gs
39 lines (30 loc) · 1.37 KB
/
binance.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
// Binance API v3 Private Request in Google Apps Script (GAS).
// By Moosy Research, see more cryptosheets on: https://sites.google.com/view/moosyresearch
function BIN_GetBalance() {
var binrequest = {
'apikey' : '•••••••••',
'secret' : '•••••••••',
'uri' :'https://api.binance.com/api/v3/',
'command' :'account',
'method' :'get',
'payload' :''
};
var response = BIN_PrivateRequest(binrequest);
Logger.log( JSON.parse(UrlFetchApp.fetch(response.uri, response.params)) );
}
function BIN_PrivateRequest(binrequest) {
function ToHex(s) { return s.map(function(byte) { return ('0' + (byte & 0xFF).toString(16)).slice(-2);}).join(''); }
function HMACSHA256HEX(s, secret) { return ToHex(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, s, secret)).toString(); }
var postdata = "timestamp="+ new Date()*1 + binrequest.payload + "",
signature = HMACSHA256HEX(postdata,binrequest.secret),
params = {
'method' : binrequest.method,
'muteHttpExceptions': true,
'headers': {
'Content-Type' : 'application/x-www-form-urlencoded',
'X-MBX-APIKEY' : binrequest.apikey,
},
};
postdata = postdata+"&signature="+signature;
return { uri: binrequest.uri+binrequest.command+"?"+postdata, params: params };
}