Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
Maybe you should start making some outputs (or console logs) to see what is actually going on in your script. –  Charlotte Dunois 1 hour ago
    
Also look into the dev tools to see if the request is correct and if you get the expected response. –  Lorenz Meyer 54 mins ago
    
Apps Script .gs script files use Logger.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

1 Answer 1

I'm not sure if this line will work in JavaScript:

/* Bring it all together */
var uri = url.concat(inputapikey).concat(apik).concat(inputnonce).concat(nonce);

String concatenation in JavaScript is done with the plus sign.

Try:

var uri = inputapikey + apik + inputnonce + nonce;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.