tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
728 stars 264 forks source link

Unecesarry ping when WebSocket is not ready #384

Closed dutu closed 5 months ago

dutu commented 5 months ago

WebsocketClient sends unncesarry ping and pong when WebSocket exists, but it's not ready . It results in unnecesarry errors like:

error: Failed to send WS ping {
  category: 'binance-ws',
  wsKey: 'spot_userData__rE3a2TtbzbjRRhrQ5i7r1xrrPof2hengrfLTcEeI1bWFCEz4L3Yj5RixKpkB',
  exception: Error: WebSocket is not open: readyState 0 (CONNECTING)

This situation can be avoided by testing readyState to be OPEN before sending the ping and pong.