我试图向KuCoin 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)有人知道我怎么能解决这个问题吗?
发布于 2022-02-25 02:10:33
在您提供的代码片段中,有几件事情看起来很奇怪,但是您所链接的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服务器时间戳,但应该足够继续运行。
祝交易好运!
https://stackoverflow.com/questions/71163252
复制相似问题