2

According to Binance GET requests require API-keys are passed into the Rest API via the X-MBX-APIKEY header. Also endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation.

My code is as follows:

componentDidMount() {
        fetch(`https://api.binance.com/sapi/v1/capital/config/getall?Signature=${encodeURIComponent(this.params.Signature)}&Timestamp=${encodeURIComponent(this.params.Timestamp)}`, {
          method: 'GET',
          headers: new Headers({
            'X-MBX-APIKEY': 'XXX'
          })


        })

where this.params.Signature is the signature which I created manually using hmac sha256. The timestamp is produced using the code Timestamp: Math.floor((new Date()).getTime() / 1000).

I get the following error in inspect tools from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

When accessing the fetch link I get the error {"code":-2014,"msg":"API-key format invalid."}

FreeLand
  • 159
  • 1
  • 3
  • 11
  • Looks like the API is not intended for using it from the client side. You might need to setup your own proxy server to achieve this. – Camilo Dec 20 '21 at 21:47
  • Take a look at these: https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome – carloswm85 Dec 20 '21 at 22:08

0 Answers0