-
-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binance APIs in the frontend & CORS #194
Comments
When directly making a request from a browser to a backend (in this case binance is the backend), CORS should be addressed by the backend. The backend essentially defines what is acceptable - in this case binance's APIs are not configured to accept this header (among many other CORS headers binance's APIs sadly are not configured for). Bybit suffers the same limitation. Using your own CORS proxy is certainly an option (but not a public one), but safer would be to have these kind of API calls be triggered by your own backend. Some explanations here from a similar discussion in my bybit connector (which works very similarly): I would also recommend nudging binance about this - perhaps increased demand will nudge them enough to prioritise configuring their APIs for CORS. Hope this helps. |
Are you on the latest version? This was fixed in #180. v2.0.21 or above. |
Also, once you get up and running, it'd be useful for others if you could write some kind of tutorial or high level summary on how to get this working in the browser (incl cors-anywhere implementation). Even a lazy example repo would be helpful. |
Hi, did you manage to make it work correctly? |
My recommendation is to make signed requests through a backend (this way your API keys are also not exposed to the browser). This would avoid the CORS limitation from binance as well as reduce risk to those API keys, although it would mean maintaining some backend APIs that your frontend can use. You would also need to consider rate limits, since your backend would be making API calls (likely from the same IP), although you would see this with cors-anywhere too. |
you need following 3 points: 1)launch "npm install cors-anywhere"
This way requests will reach the local proxy as first, then the proxy will handle the cors headers |
tiagosiebler and sergiocard thank you for your help! |
Hi, i'm using this library on browser. I know its intented for backend use but i'm prototyping and would to use it in browser.
I'm using
const client= new MainClient({
api_key: '*******',
api_secret: '*****',
beautifyResponses: true
})
client.testNewOrder(buyOrderRequest)
but i get following CORS errors.
Should the POST request contains an Access-Control-Request-Headers header for "x-mbx-apikey" header?
Looking into binance dev area it seems it's possible to make browser side calls only for public apis.
Can you confim? I'm thinking i could use a local proxy to forward local browser calls to binance server instead?
for example with cors-anywhere npm module
The text was updated successfully, but these errors were encountered: