Ping user data stream

I’m reading docs at https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-api.md#user-data-stream-requests and I have a question: WebSocket uses ping event to send a pong response, why documentation says to send a ping using the code below?

{
  "id": "815d5fce-0880-4287-a567-80badf004c74",
  "method": "userDataStream.ping",
  "params": {
    "listenKey": "xs0mRXdAKlIPDRFrlPcw0qI41Eh3ixNntmymGyhrhgqo7L6FuLaWArTD7RLP",
    "apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
  }
}

What is the difference? I need to implement both or not?

Hey,
Could you provide more context on the specific code you’re comparing the ping to?
The code you shared is related to pinging a user data stream to maintain its activity as explained in the documentation.

Hi.

Ping in the context of user data stream means to keep your listen key alive, so you can still receive updates on your account.
Ping in the context of the websocket is keeping your ws connection alive.

So yes, if you want to keep both your listen key and ws connection running, you need to do both.

Hope that helps.

2 Likes