Unable to receive WebSocket ping frames from Binance's spot and futures.


I am trying to use the github.com/gorilla/websocket library of the Go language to code a WebSocket connection to obtain real-time information on spot and futures transactions.

I noticed that “The WebSocket server will send a ping frame every 3 minutes. If the WebSocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected. Unsolicited pong frames are allowed.” is mentioned in the document.

So, I tried the method:

            msgType, _, err := w.conn.ReadMessage()

			if err != nil {
				logger.Error("Read error: %s", err)
				time.Sleep(TimeIntervalSecond * time.Second)

			if msgType == websocket.PingMessage {
				w.conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(10*time.Second))
			} else {


However, I did not receive a WebSocket message of type ping. And without sending pong to the server, I can still get data from the server for several hours.

I searched the forum for similar issues:

Not receiving PING frame for Futures Websocket, as mentioned in their documentation
Not receiving ping frame from Binance for Websocket Futures Market Stream#7

But after a few months, the document does not seem to be updated. At present, do I need to set a timer to send pong messages to the server regularly, regardless of whether I receive the ping message sent by the server, or whether it is possible in the subsequent update, as stated in the document, “every 3 minutes or 5 minutes, the server sends pong messages to customers Send a ping message”, hope to receive your reply as soon as possible.

Thanks in advance.

Screenshot 2021-04-05 at 7.49.13 PM

Using Python’s websocket library, i am able to receive ping from the server on a 5 minutes interval which is stated on the documentation (https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams).
Socket: wss://fstream.binance.com/ws/ethusdt@kline_15m

Not familiar with go but after reading this documentation (https://chromium.googlesource.com/external/github.com/gorilla/websocket/+/0ec3d1bd7fe50c503d6df98ee649d81f4857c564/doc.go),
“// Connections handle received ping messages by calling the handler function set with the SetPingHandler method. The default ping handler sends a pong message to the peer.” the library will response with a pong message by default. I guess if you want to check if you have received the ping message, you have to declare a setPingHandler method.

So, what’s the structure of the pong frame. Can you show me an example by using python? Please

It uses the standard format as shown above. However, most python websocket libraries handles that for you which means you do not have to do it yourself.