Skip to content

Instantly share code, notes, and snippets.

@SSARCandy
Last active December 30, 2017 04:14
Show Gist options
  • Save SSARCandy/b06ce23e72534ee7973188b5a86456cb to your computer and use it in GitHub Desktop.
Save SSARCandy/b06ce23e72534ee7973188b5a86456cb to your computer and use it in GitHub Desktop.
CEX.IO private API auth in Google apps scripts (google sheet)
function cex_auth(command, user_id, key, secret, callback) {
var uri = "https://cex.io/api/";
var nonce = new Date().getTime();
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, nonce.toString()+user_id+key, secret);
var stringSignature = signature.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('').toUpperCase();
var params = {
"method": "post",
"payload": {
"key": key,
"signature": stringSignature,
"nonce": nonce.toString()
}
};
var response = UrlFetchApp.fetch(uri+command, params);
var dataAll = JSON.parse(response.getContentText());
callback(dataAll);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment