Unrelated
Sorry to leave this here, not sure how to message people on github. I am a big python guy and can understand your code here. However, is the same thing possible in Javascript? I have been trying for two days now and I cannot get the binance api to work with javascript. I use a function like so:
function httpGetAsync(theUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
and attempt to get the server time with
url = 'https://www.binance.com/api/v1/time'
console.log(httpGetAsync(url))
but I get an error in the console of my server:
XMLHttpRequest cannot load https://www.binance.com/api/v1/time. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://myserver.com' is therefore not allowed access.
where myserver.com is my website. I see that you also use Javascript, perhaps you could provide some insight? Again sorry for placing this here.
Hey @dmacmillan,
Essentially this is a CORS error and means that the Binance API isn't returning and 'Access-Control-Allow-Origin' header, or with a value that includes your server. I assume you're using Chrome which is restricting these type of requests be default. You will probably find that Firefox will work.
For now you can add a Chrome plugin which disables this check something like this plugin or this one, or search CORS on the Chrome Webstore.
A more general solution would be to submit a request to Binance to update their API response headers to include an 'Access-Control-Allow-Origin' header ideally with value '*' allowing all hosts.
If you send the requests server side you won't have any issues, it's only from the browser.
Hope that helps.
Closing issue