I have a problem with reverse engineering a php script to work with google spreadsheet. First I will show you the original php code and then show you my solution. At this point I have no indication as to what is wrong with my code.
1 Original php code. Source: bittrex.com/Home/Api
$apikey='xxx';
$apisecret='xxx';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
2 Reverse engineered google appscript code (just pure Javascript) of 1.
/* Generate Nonce */
function nonceGen() {
var d = new Date();
var timeStamp = d.getTime();
return timeStamp;
}
/* Encode with standard HMAC-SHA512 */
function signKey(url, secret) {
var signature = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, url, secret));
return signature;
}
function getBalances(apik, apis) {
/* Set important variables */
var url = 'https://bittrex.com/api/v1.1/account/getbalances';
var inputapikey = '?apikey=';
var inputnonce = '&nonce=';
var nonce = nonceGen();
/* Bring it all together */
var uri = url.concat(inputapikey).concat(apik).concat(inputnonce).concat(nonce);
/* Sign the message */
var sign = signKey(uri,apis);
/* Set apisign as header */
var headers = { 'apisign' : sign };
var options = { 'method' : 'get', 'headers' : headers };
/* Retrieve response and parse the json into the data variable */
var response = UrlFetchApp.fetch(uri, options);
var data = JSON.parse(response.getContentText());
/* Output on screen */
Logger.log(data);
}
I can't seem to figure out what the problem is. There seems to be no output on the screen at all. Not even an error. Hopefully I can get some bugtesting suggestions.
.gs
script files useLogger.log('some text: ' + myVariable);
to print output to the Log. Use View, Log to see the output. Or you can choose a function, and click the bug to run the debugger. – Sandy Good 27 mins ago