Hello,
I’m writing a fetch query but get an error in the notebook. I check the browser’s Network tab. The request returns 200 with a valid response. But in the notebook, I get an error:
SyntaxError: Unexpected end of input
fetch("https://www.bitmex.com/api/v1/trade?symbol=.BVOL&count=100&columns=price", {
headers: {"content-type": "application/json"},
mode: "no-cors"
}).then(response => {
return response.json();
});
What is the difference between the browser’s network request and the notebook?
Thanks.
Hi @dnprock , it seems like they don’t offer CORS on their public API for security reasons.
opened 10:19AM - 22 Aug 18 UTC
closed 04:32PM - 28 Aug 18 UTC
Failed to load https://testnet.bitmex.com/api/v1/user/walletHistory: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested...
But you can use a proxy. I’ve setup one for you on glitch. You can run this on Observable now, there will be a few seconds to warmup glitch
data = await fetch(
"https://bitmex-proxy.glitch.me/api/v1/trade?symbol=.BVOL&count=100&columns=price"
).then(r => r.json())
Here is the source code on glitch
Combining automated deployment, instant hosting & collaborative editing, Glitch gets you straight to coding so you can build full-stack web apps, fast
1 Like
Heh, seeing your comment jogged my memory.
when I go to this API address with my browser I can visualise the JSON file related to it.
I tried to access it by Observable using the cors-anywhere.herokuapp.com but I get a SyntaxError: Unexpected end of JSON input.
here is notebook:
Any chance to make it work?
Thanks
@radames @bgchen thanks for the reference.