【问题标题】:how to read the error of a callback function in node.js如何读取node.js中回调函数的错误
【发布时间】:2018-05-04 05:22:29
【问题描述】:

我正在编写一些代码以调用 api 并获取一些数据......该代码有一个 github 存储库https://github.com/kwiksand/yobit,我调用了一个名为 addTrade 的函数/方法(在 index.js 下)。 ..

通过 API 密钥和安全性后,我有以下代码:

  privateYoBit.addTrade(function(err,data){
    console.log(data);
    console.log(err)
    },"eth_btc","buy",0.04, 0.02);
  }

我收到以下回复:

{ success: 0, error: 'invalid method' }
null

我的问题是:

  1. console.log(err) 返回一个“空值:是不是说明代码没问题,问题出在另一端(API)?
  2. 如何调试/优化“无效方法”返回?

非常感谢任何帮助/支持

问候

【问题讨论】:

    标签: javascript node.js api error-handling callback


    【解决方案1】:

    阅读source of the mentioned library,作者似乎将以下参数作为请求的一部分发送:

    var params = {
        symbol: symbol,
        type: type,
        amount = amount,
        price = price
    }
    

    但是,阅读the documentation for the API,他们期望以下 4 个参数:

    pair   : pair (example: ltc_btc)
    type   : transaction type (example: buy или sell)
    rate   : exchange rate for buying or selling (value: numeral)
    amount : amount needed for buying or selling (value: numeral)
    

    也许尝试调整库以符合 API 期望的参数?

    如果我是你,我会非常小心使用不受信任、未经测试的 API 进行交易...

    【讨论】:

    • 我既没有使用过 Yobit API 也没有使用过这个库,所以我只能给出一些猜测。尝试将index.js 中的参数定义更改为 API 所期望的?更改params.symbol -> params.pairparams.price -> params.rate
    • 这很有意义...我实际上是 node.js 的新手并试图对库进行逆向工程,所以我可以信任/修改它;)如果我查看 Yobit 的参数网站(API 源),我应该如何调用来发起交易?有点困惑如何通过 url 中的身份验证...yobit.net/tapi ???? Authentication 谢谢
    • 对不起,我从来没有使用过 Yobit API,此时我能做的就是和你一样,阅读文档。看起来每个请求都需要传递 API 密钥,并通过 SHA512 散列所有发布参数。这就是您链接我的部分所述。
    猜你喜欢
    • 1970-01-01
    • 2019-06-09
    • 2021-05-30
    • 2017-07-14
    • 2014-01-31
    • 1970-01-01
    • 2014-03-29
    • 2016-03-04
    • 1970-01-01
    相关资源
    最近更新 更多