如何将 HMAC SHA 256 密钥发送到币安 API?

问题描述

我写了这段代码

api_key = "https://api.binance.com/api/v3/myTrades??X-MBX-APIKEY="+config.API_Key+"&signature="+config.Secret_Key

并得到这个错误

{"code":-2014,"msg":"API-key format invalid."}

这是binance api的文档 https://binance-docs.github.io/apidocs/spot/en/#endpoint-security-type

解决方法

您需要将 X-MBX-APIKEY 作为请求标头而不是 GET 参数传递。

不幸的是,您的代码没有显示您如何构建请求,但这里有一个使用 axios 的示例:

axios({
    url: 'https://api.binance.com/api/v3/myTrades',method: 'get',headers: {
        'X-MBX-APIKEY': config.API_Key
    }
}).then((response) => {
    console.log(response);
})