签署API密钥(bittrex api)[NODE]

问题描述 投票:0回答:1

所以我想尝试对bittrex进行API调用。似乎需要我签署api密钥。

我有

export const account_balance_for_currency = (currency) =>
    `https://bittrex.com/api/v1.1/account/getbalance?apikey=${signedKey}&currency=${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,因为这是唯一缺少的部分。

node.js api signed
1个回答
0
投票

您必须签署整个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}&currency=${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);
  });
© www.soinside.com 2019 - 2024. All rights reserved.