Search code examples
node.jsapihmacbinance

Binance - msg: 'Signature for this request is not valid.'


I've been trying to make an API request to the Binance using NodeJs API as per this documentation but I keep getting the following response and I don't know why.

[Object: null prototype] {
  code: -1022,
  msg: 'Signature for this request is not valid.'
}

I've looked around the internet for a solution but all of the "fixes" do not seem to work.

Here is the actual function that makes the request to Binance:

Biance API

And here is my code that calls the function:

    const result = await binance.futuresTransferAsset("USDT", "1", [Enum.UMFUTURE_MAIN])

I've been stuck trying to debug this but haven't had any success so if anyone knows please help me out.

And here is the actual function:

futuresTransferAsset: async ( asset, amount, type ) => {
    let params = Object.assign( { asset, amount, type } );
    console.log(params)
    return promiseRequest( 'v1/futures/transfer', params, { base:sapi, type:'SIGNED', method:'POST' } );
}

Solution

  • According to Binance API documentation, signature is required for the endpoint which you try to access.

    Hence include your signature in the request body inorder to get a valid response. Which means that you must sign your request using the HMAC SHA256 standard.

    If the error still persists, I highly suggest you to use the official API of Binance instead of using some other random libraries.

    You can get more information here