feat(v3.0.0): Introduce Binance WebSocket API, introduce multiplex WebSocket client, bump dependencies, remove some deprecated endpoints#509
Conversation
… Begin preparing base WS client/
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…g, fix emittable bug with arrays, test each topic
…r new websocket events, create examples for all product groups
…es, add more req/res types
I was largely thinking about account-level commands (submitting orders, changing leverage, etc), which will always require auth, naturally. Part of the motivation for using the WS API is latency, and naturally for market data if latency is important you should be consuming events (as a subscriber), not polling data at intervals (even if the ws api makes it faster than pure REST API). I also misunderstood what you were doing when I first read your question. I thought you were subscribing to market data as a consumer (which should be via the WebsocketClient). Perhaps auth should remain optional for WebSocket API commands that don't require it (market data). Should be straight forward to implement around how the WebsocketAPIClient sends each command... I'll look into it. In the meantime I've also improved internal checks to make sure there's a clearer error message if API keys are missing when trying to authenticate the WS API. |
…require auth. add better message when keys are required but missing
|
Published binance@3.0.0-beta.16:
Thank you to everyone involved in testing & feedback, it's been extremely helpful! If you notice anything else that doesn't look normal, please keep opening issues. |
I have two questions about the wsAPI execution log above:
|
|
What is the difference between the two methods of the WebsocketClient class:
I am currently calling |
=>
Even though I passed in The execution result is still abnormal: |
This public connectWSAPI(wsKey: WSAPIWsKey, skipAuth?: boolean): Promise<unknown> {
if (skipAuth) {
return this.assertIsConnected(wsKey);
}
/** This call automatically ensures the connection is active AND authenticated before resolving */
return this.assertIsAuthenticated(wsKey);
}Regarding the difference, as you can see here, the connectWSAPI call is wrapped around the assert methods. Those methods are special in that they're promise-wrapped, although at this point the |
Update optional wsapi futures
You may misunderstood me:
So, my question is actually why a failed request from a certain ws_api leads to the disconnection of the ws connection? |
…i calls, reduce excessive resolveEmittable traces
Apologies for the delay. At first I thought it was related to not handling the promise returned by the sendWSAPIRequest method, but I actually can't reproduce the issue with the latest changes. I think it might've been related to sending an invalid sign request when no keys are present - I've recently added a guard to prevent even trying it if credentials aren't available, so perhaps that fixed your issue as a side effect. Perhaps already with the changes in the .16 beta release. I've just published another beta release with the latest code, can you give it a try? Thanks for all the issues you've reported! Published binance@3.0.0-beta.17:
Thank you to everyone involved in testing & feedback, it's been extremely helpful! If you notice anything else that doesn't look normal, please keep opening issues. |
|
the I found this by accident while looking through the binance-connector-js codes: https://github.com/binance/binance-connector-js/blob/master/common/src/utils.ts#L294 |
…bSocket client, bump dependencies, remove some deprecated endpoints
…sting https agent configuration
|
Hey @aweiu apologies for the delay, had some time away. Thanks for pointing that out. Yes, it was meant initially as a convenience flag for those that didn't have more advanced needs, while it was already possible to inject your own https agent in the constructor of the REST clients (second parameter, passed through to axios). Might be a bit misleading though that it wasn't documented and I've been meaning to improve it. I've revised the logic a bit to consider an existing https agent. Also added a test to validate that it's working as expected. Just a simple check that certificate pinning correctly rejects the request when using an incorrect public key hash, while keep alive is active (confirming that both agent configurations were merged, not overwritten). Thanks for all the feedback! Let me know if there's anything else! Will look to release this branch this week, since it seems most of the important issues have been ironed out! |


Summary
This major release brings major upgrades to the Node.js, TypeScript & JavaScript SDK for Binance's REST APIs and WebSockets. The WebSocket API is here - send orders at a lower latency over a dedicated WebSocket connection, without the complexity of managing WebSockets. Use the
WebsocketAPIClientclass to use the WebSocket API like a REST API, with virtually no additional complexity.High Level Changes
errorhas been renamed toexceptionreplyhas been renamed toresponseWebsocketAPIClient.customSignMessageFn()parameter to WebsocketClient and REST clients.Major Changes
WebsocketAPIClient
WebsocketAPIClientclass, wrapped around theWebsocketClient's WS API capabilities.Multiplex WebsocketClient
WebsocketClient, designed around multiplex WebSocket subscriptions.WebsocketClientV1
Breaking / Potentially Breaking Changes
{ useTestnet: true }config to{ testnet: true }WebsocketClienthas been renamed toWebsocketClientV1.DefaultLoggermethods, in line with my other SDKstrace|info|error.sillylevel before this release, thetracelevel is disabled/silent by default.event.ws.target.urlshould useevent.wsUrlinstead.{ useTestnet: true }config to{ testnet: true }{ testnet: true }as part of the REST client options instead.get24hrChangeStatististics(), useget24hrChangeStatistics()instead.getAccountComissionRate(), usegetAccountCommissionRate()instead.updateAutoInvestmentPlanOld(), useupdateAutoInvestmentPlan()instead.submitAutoInvestmentPlanOld(), usesubmitAutoInvestmentPlan()instead.SpotClientexportMainClientinstead (it is the same).High level checklist