-
Notifications
You must be signed in to change notification settings - Fork 19
/
okex.gs
38 lines (33 loc) · 1.5 KB
/
okex.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
// OKEX API Private Request in Google Apps Script (GAS).
// By Moosy Research, see more cryptosheets on: https://sites.google.com/view/moosyresearch
function OKX_GetBalance() {
var okxrequest = {
'apikey' : '•••••••••',
'secret' : '•••••••••',
'adattrib' : '•••••••••', // Passphrase
'uri' : 'https://www.okex.com',
'version' : '/v3/',
'command' : '/api/account/v3/wallet',
'method' : 'GET',
'payload' : ''
};
var response = OKX_PrivateRequest(okxrequest);
Logger.log( JSON.parse(UrlFetchApp.fetch(response.uri, response.params)) );
}
function OKX_PrivateRequest(okxrequest) {
function HMACSHA256B64(s, secret) { return (Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, s, secret))); }
var timestamp = Utilities.formatDate(new Date(), 'GMT -1', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\''),
params = {
'method' : okxrequest.method,
'muteHttpExceptions' : true,
'headers': {
'OK-ACCESS-KEY' : okxrequest.apikey,
'OK-ACCESS-SIGN' : HMACSHA256B64(timestamp + okxrequest.method + okxrequest.command, okxrequest.secret),
'OK-ACCESS-TIMESTAMP' : timestamp,
'OK-ACCESS-PASSPHRASE': okxrequest.adattrib,
'Accept' : 'application/json',
'Content-Type' : 'application/json'
}
}
return { uri: okxrequest.uri + okxrequest.command , params: params};
}