Search code examples
apikeyhmacbinance

how to send HMAC SHA 256 Secret key to binance api?


I write this code:

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

and get this error:

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

and this the documentation of binance api https://binance-docs.github.io/apidocs/spot/en/#endpoint-security-type


Solution

  • You need to pass the X-MBX-APIKEY as a request header, not as a GET param.

    Unfortunately your code doesn't show how you build the request, but here's an example using axios:

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