KuCoin API - TypeError: request.charAt is not a function

KuCoin API - TypeError: request.charAt is not a function

我正在向库币API请求查询余额。我正在使用此处找到的 NodeJS API,但每当我执行代码时,我都会收到错误消息。

这是代码片段

            data().then(api => {

            const apiKey = api.api_key;
            const apiSecretKey = api.api_secret;
            const contactId = api.contact_id;
            const exchange = api.exchange;
            const passphrase = 'Passphrase';

            /** Init Configure */
            const config =
            {
                key: apiKey, // KC-API-KEY
                secret: apiSecretKey, // API-Secret
                passphrase: passphrase, // KC-API-PASSPHRASE
                environment: "live"
            }

            API.init(require(config));

            if (apiKey && exchange === "KuCoin-Futures") {

                console.log("KuCoin Balance")


                async function getBalance() {

                    try {
                        let r = await API.getAccountOverview()
                        console.log(r.data)
                      } catch(err) {
                        console.log(err)
                      } 

                }

                return getBalance()

            }
        });

我在控制台日志中收到以下错误

TypeError: request.charAt is not a function
at Function.Module._resolveLookupPaths (internal/modules/cjs/loader.js:617:15)

有谁知道我该如何解决这个问题?

您提供的代码片段中有几处看起来很奇怪,但您链接的 kucoin-node-api 库中的示例代码应该可以正常工作。如果你正在使用那个,试试这个应该显示你的帐户信息的片段:

const api = require('kucoin-node-api');

const config = {
  apiKey: 'YOUR_KUCOIN_API_KEY',
  secretKey: 'YOUR_KUCOIN_API_SECRET',
  passphrase: 'YOUR_KUCOIN_API_PASSPHRASE',
  environment: 'live'
};

api.init(config);

api.getAccounts().then((r) => {
  console.log(r.data);
}).catch((e) => {
  console.log(e);
});

如果您使用的是不同的库,kucoin-node-sdk 也许(根据您的代码片段判断),然后尝试正确配置它:

config.js 文件:

module.exports = {
  baseUrl: 'https://api.kucoin.com',
  apiAuth: {
    key: 'YOUR_KUCOIN_API_KEY',
    secret: 'YOUR_KUCOIN_API_SECRET',
    passphrase: 'YOUR_KUCOIN_API_PASSPHRASE'
  },
  authVersion: 2
}

和你的main.js(或任何名称):

const API = require('kucoin-node-sdk');

API.init(require('./config'));

const main = async () => {
  const getTimestampRl = await API.rest.Others.getTimestamp();
  console.log(getTimestampRl.data);
};

main();

上面的代码只会向您显示 KuCoin 服务器时间戳,但应该足以继续进行。

祝交易顺利!