-
-
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
Documentation on running in browser with webpack #144
Comments
Hi there - the only docs on that so far are here: If you include the bundled js file with a script tag on a page, you'll have a global variable called |
Hi @tiagosiebler I'd be happy to contribute some docs and fixes as necessary.. I'm trying to get websocket data collection working. So it appears there are some issues here due to the websocket implementation by isomorphic-ws for the browser not having a
Notes:
So I was able to get a readable browser package that I could insert debug logs into by changing https://github.com/tiagosiebler/binance/blob/master/webpack/webpack.config.js#L16 from What I found was that Debugging this is really painstaking though as I have to replace the |
Thanks for spending time on this! You can override the default logger by passing your own implementation into the second parameter of the WebsocketClient constructor. There's an example in the websocket demo in the readme: const logger = {
...DefaultLogger,
silly: (...params) => { console.log(...params); },
};
const wsClient = new WebsocketClient({
api_key: key,
api_secret: secret,
beautify: true,
}, logger); Something like this should enable the silly logger again.
It must be this part that's throwing: I'm not sure yet how to approach this. If I remember right, the browser websocket implementation doesn't provide ways to send the ping/pong frames: https://stackoverflow.com/questions/10585355/sending-websocket-ping-pong-frame-from-browser The main purpose of this logic is to send something upstream at an interval and start a timer. If the server doesn't send a reply downstream before the timer expires, we assume the connection dropped and being the resurrection process (by first closing the existing connection): This works well in node where those functions trigger pong frames, but an alternative will be needed for browsers where those functions don't exist... anything to trigger some kind of server response on the same stream. If it's reliable enough, it could even replace the ping/pong heartbeats. |
Thanks for the detailed response @tiagosiebler ! I may try to get together a PR working to resolve the issues if I have time over the next couple of weeks. I'm wondering how you'd feel about removing isomorphic-ws as a dependency (it hasn't been updated in 3 years) with I haven't investigated this too much yet, I just noticed isomorphic-ws doesn't support ping/pong, or terminate, so it might defeat the purpose of using it in the first place if there are a lot of things that have to be handled differently. |
That'd be great, thanks!
I'm open to alternatives as long as they don't introduce unnecessary dependencies.
The ping/pong limitation is actually due to the websocket implementation in browsers. This library just points to it, if you're in a browser environment, but the limitation comes from the browser API: |
How to build browser binanceapi.js
Go to dist/ directory where binanceapi.js is located. because its compiled as module, you need to import it in your project like this: or in html it will create a
|
No need to |
@tiagosiebler Help please. I want to use your SDK in the browser, but I get an error when I try to install it. How do I solve the problem? |
Hi, I'm interested in getting this running in my browser (I know I can get around the cors issues with CORS-proxy, so I'm not too worried about that). I'm wondering if you've documented any steps to get it built with Webpack though.
The text was updated successfully, but these errors were encountered: