-
Notifications
You must be signed in to change notification settings - Fork 19
/
auth.gs
57 lines (49 loc) · 1.39 KB
/
auth.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function bytesToHex(bytes) {
return bytes.reduce(function (acc, curr) {
return acc + ("0" + (curr < 0 ? curr + 256 : curr).toString(16)).slice(-2);
}, "");
}
function getAccountBalances() {
const apiKey = "";
const apiSecret = "";
const request = "/api/v4/trade-account/balance";
const hostname = "whitebit.com";
const nonce = Date.now();
const nonceWindow = true;
const data = {
ticker: "BTC",
request: request,
nonce: nonce,
nonceWindow: nonceWindow,
};
const dataToString = JSON.stringify(data);
const payload = Utilities.base64Encode(dataToString);
const hmac = Utilities.computeHmacSignature(
Utilities.MacAlgorithm.HMAC_SHA_512,
payload,
apiSecret
);
const signature = bytesToHex(hmac);
const options = {
hostname: hostname,
request: request,
method: "POST",
headers: {
"Content-Type": "application/json",
"X-TXC-APIKEY": apiKey,
"X-TXC-PAYLOAD": payload,
"X-TXC-SIGNATURE": signature,
},
muteHttpExceptions: true,
payload: dataToString,
};
const url = `https://${hostname}${request}`;
const response = UrlFetchApp.fetch(url, options);
const responseCode = response.getResponseCode();
if (responseCode === 200) {
const data = JSON.parse(response.getContentText());
console.log(data);
} else {
console.log("Error: " + responseCode + " " + response.getContentText());
}
}