所以我想尝试对bittrex进行API调用。似乎需要我签署api密钥。
我有
export const account_balance_for_currency = (currency) =>
`https://bittrex.com/api/v1.1/account/getbalance?apikey=${signedKey}¤cy=${currency}&nonce=${nonce()}`;
现在我把钥匙放在process.env
上,密码放在process.env
上
试图这样做
const signedKey = crypto
.createHmac('sha512', `${process.env.BITTREX_SECRET}`)
.update(`${process.env.BITTREX_API_KEY}`)
.digest('hex');
但它不起作用,我没有找到一个很好的方法来按我的意愿去做。
我一直在接受success: false, message: 'APISIGN_NOT_PROVIDED'
任何建议/解决方案?我不想将现有的npm
包用于api,因为这是唯一缺少的部分。
您必须签署整个API调用,而不是API密钥。
const Crypto = require('crypto');
const account_balance_for_currency = `https://bittrex.com/api/v1.1/account/getbalance?apikey=${process.env.BITTREX_API_KEY}¤cy=${currency}&nonce=${nonce()}`;
const signature = Crypto.createHmac('sha512', process.env.BITTREX_SECRET)
.update(account_balance_for_currency)
.digest('hex');
然后,您可以使用像axios这样的HTTP客户端发送完整请求。 Bittrex需要请求的apisign
头中的签名。
const axios = require('axios');
axios({
method: 'get',
url: account_balance_for_currency,
headers: {
apisign: signature
}
})
.then(function (response) {
console.log(response);
});