dparlevliet / node.bittrex.api

Node Bittrex API is an asynchronous node.js library for the Bittrex API, the data can be received either via GET request or Stream.
MIT License
253 stars 100 forks source link

node.bittrex.api - Error while calling buylimit function #102

Closed xFABRIKA closed 6 years ago

xFABRIKA commented 6 years ago

I am conducting some testing and when I call the buylimit function I get an error.

My code is the following:

var assert = require('assert');
var bittrex = require('node.bittrex.api');
var fs = require('fs');
var config = JSON.parse(fs.readFileSync('./config.json'));

bittrex.options({
  'apikey' : config.api.apiBittrex.key,
  'apisecret' : config.api.apiBittrex.secret,
});

bittrex.buylimit({ market : tradingPair, quantity : quantityToBuy, rate : unitPrice }), function( data ) {
  console.log("Order Executed"
}

this generate an order in Bittrex, but the code throw an error pointing to the following code in node.Bittrex.api.js (error in the last "callback" as highlighted below).

var sendRequestCallback = function(callback, op) {
    var start = Date.now();

    request(op, function(error, result, body) {
      ((opts.verbose) ? console.log("requested from " + op.uri + " in: %ds", (Date.now() - start) / 1000) : '');
      if (!body || !result || result.statusCode != 200) {
        var errorObj = {
          success: false,
          message: 'URL request error',
          error: error,
          result: result,
        };
        return ((opts.inverse_callback_arguments) ?
          callback(errorObj, null) :
          callback(null, errorObj));
      } else {
        result = JSON.parse(body);
        if (!result.success) {
          // error returned by bittrex API - forward the result as an error
          return ((opts.inverse_callback_arguments) ?
            callback(result, null) :
            callback(null, result));
        }
        return ((opts.inverse_callback_arguments) ?
          callback(null, ((opts.cleartext) ? body : result)) :
          callback(((opts.cleartext) ? body : result), null));   // -> ERROR HERE
      }
    });
  }

the error says:

Exception has occurred: TypeError TypeError: callback is not a function at Request._callback (c:\00 - Projects\node_modules\node.bittrex.api\node.bittrex.api.js:138:11) at Request.self.callback (c:\00 - Projects\node_modules\request\request.js:186:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request.<anonymous> (c:\00 - Projects\node_modules\request\request.js:1163:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at IncomingMessage.<anonymous> (c:\00 - Projects\node_modules\request\request.js:1085:12) at Object.onceWrapper (events.js:313:30) at emitNone (events.js:111:20)

any help would be much appreciated

dparlevliet commented 6 years ago

There's a bug in that code you supplied. The error is saying you're calling buylimit without a callback function, and if you look at the line you'll notice the ) isn't at the end of the line.