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."}