Last active
December 30, 2017 04:14
-
-
Save SSARCandy/b06ce23e72534ee7973188b5a86456cb to your computer and use it in GitHub Desktop.
CEX.IO private API auth in Google apps scripts (google sheet)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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