Created
February 3, 2020 14:12
-
-
Save helloluis/d121d91664525f020663afc05f5f46ed to your computer and use it in GitHub Desktop.
Kraken
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
var Kraken = function(){ | |
this.host = "https://api.kraken.com"; | |
this.tab = "kraken"; | |
this.balances = {}; | |
this.initialize = function() { | |
var pp = PropertiesService.getScriptProperties(); | |
this.key = pp.getProperties()['kraken_key']; | |
this.secret = pp.getProperties()['kraken_secret']; | |
}; | |
this.createSignature = function(endpoint, nonce, message) { | |
var hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256,nonce); // you need to include the params in the signature | |
var secret = Utilities.base64Decode(this.secret); | |
var hmac = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, hash, secret); | |
return Utilities.base64Encode(hmac); | |
}; | |
this.getBalances = function() { | |
var endpoint = "/0/private/Balance"; | |
var url = this.host + endpoint; | |
var message = ""; | |
var nonce = ""+new Date().getTime(); | |
var signature = this.createSignature(endpoint, nonce, message); | |
var headers = { | |
'API-Key' : this.key, | |
'API-Sign' : signature, | |
'nonce' : nonce | |
}; | |
var options = { | |
"method" : "post", | |
"muteHttpExceptions": true, | |
'Content-Type' : 'application/x-www-form-urlencoded', | |
'User-Agent' : 'BloomX Google Sheet Agent', | |
"headers" : headers, | |
"payload" : JSON.stringify({ "nonce" : parseInt(nonce) }) | |
}; | |
Logger.log(url); | |
Logger.log(options); | |
var response = UrlFetchApp.fetch(url, options); | |
var resp = JSON.parse(response.getContentText()); | |
Logger.log(resp); | |
return this.balances; | |
}; | |
// run this every time the object is created | |
this.initialize(); | |
}// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment