jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.58k stars 769 forks source link

Use this library directly in the browser? #38

Closed webqap closed 6 years ago

webqap commented 6 years ago

Hi. What would be the best way to use this library in the browser?

jaggedsoft commented 6 years ago

Not possible. No exchanges allow connections to their API via the browser or plugins due to CORS/cross origin security issues

jaggedsoft commented 6 years ago

https://github.com/binance-exchange/node-binance-api/issues/27

webqap commented 6 years ago

Ah yes that is true.

Though I think you can bypass the CORS issues by creating a custom dns/hosts entry on your local machine. For example:

cors.binance.com 127.0.0.1

Then the browser wouldn't complain anymore.

Thanks for getting back!

sadburai commented 3 years ago

hi, I was wondering today, how to implement the library in my browser. Since this post is 3 years, old, is this still not possible?

jaggedsoft commented 3 years ago

it can be done using electron and vue i believe, and there's a couple new executable build tools as well. haven't really stayed on top of this but I have done it.

You can also make a CORS wrapper on a webserver (or serverless) to act as a proxy since binance forbids browser requests except on binance.com. This way you can run without electron, in the native browser, and still make connections. I started on this project but only got a few functions and websocket working. I can share the source, but not my proxy. Basically just need the data from Binance without going through binance.com

jaggedsoft commented 3 years ago

for nginx there are reverse websocket proxies as well and I managed to get one working on apache

Reverse proxy example: instead of accessing wss://stream.binance.com/klines/btcusdt I access wss://mydomain.com/stream/klines/btcusdt for example, and I don't even have a https certificate since cloudflare handles that for me (flexible ssl)

sadburai commented 3 years ago

ok, thank you! amI still trying to figure out if it's possible to create one single javascript file from the node package that I could embed in a Githubissues.

  • Githubissues is a development platform for aggregating issues.