TypeError:第一个参数必须是字符串,Buffer,ArrayBuffer,Array或类似数组的对象。使用API​​ nodejs

时间:2017-05-16 22:20:36

标签: javascript node.js

尝试从Gdax API获取事务列表([link] [1]):以下是该方法的文档:

var accountID = '7d0f7d8e-dd34-4d9c-a846-06f431c381ba';
authedClient.getAccountHistory(accountID, callback);
// For pagination, you can include extra page arguments
authedClient.getAccountHistory(accountID, {'before': 3000}, callback);

我认为问题出在回调中,但我不明白如何修复它。

这是我的实施:

self.getTransactions = function(options, callback) {

  var key = options.key;
  var b64secret = options.secret;
  var passphrase = options.passphrase;

  var Gdax = require('gdax');
  var authedClient = new Gdax.AuthenticatedClient(
    key, b64secret, passphrase);

  var accountID = '32fb94c4-cda2-52f1-9bae-1866a0605789';
  authedClient.getAccountHistory(accountID, function(err, response, transactions) {
    let details;
    details = {
      timestamp: util.timestampNow(),
      error: err.message,
      data: []
    };
    if (err || resp.statusCode !== 200) {
      let error = err || new Error(`Error ${resp.statusCode}: ${resp.body}`);
      result.error = error.message;
      return callback(error, result);
    }
    _.each(transactions, function(transaction) {
      let data = {
        transaction_id: transaction.id,
        total: transaction.amount,
        type: transaction.type
      };
      details.data.push(data);
    });
    callback(null, details);
  });

};

0 个答案:

没有答案