Websocket Heartbeat or Ping

Normally websocket connections require a heartbeat message to be sent by client every N seconds.

  1. Does Upstox websocket also needs it?
  2. What is the format of heartbeat message? Is it just the word “ping”?
  3. How frequently should the client send the heartbeat message?
  4. If heartbeat is needed, please update the documentation.

@priteshmhatre

Yes, our Upstox WebSocket connections utilize heartbeat messages to maintain the connection’s aliveness. Most well-known WebSocket client libraries across various programming languages handle heartbeat messages automatically. These libraries manage the sending and receiving of heartbeat messages behind the scenes, ensuring your connection remains active without any additional code for heartbeats on your part.

We recommend selecting a reputable WebSocket client library that suits your development environment and language preferences to seamlessly handle these heartbeats. By doing so, you can focus on consuming the updates from our feed without worrying about the underlying connection maintenance.

For examples and guidance on WebSocket implementation, please refer to our sample implementation at: Sample Implementation | Upstox Developer API. This resource should provide you with the necessary information to get started and make the most of our WebSocket services.

If you have any further questions or require additional assistance, please don’t hesitate to reach out.

Thanks!

Your explanation is not acceptable. Which libraries to use is the choice of the user (not api provider).

Heartbeat message formats can also differ, we have worked with so many brokers. Many of them have different formats.

So it must be properly documented in your websocket connection docs.

Before you try to prove me wrong, here are some brokers documentation.

Angel

Zerodha
https://kite.trade/docs/connect/v3/websocket/

@priteshmhatre

The ping-pong mechanism for heartbeat is already part of our implementation but wasn’t documented. We’ll make sure to update the documentation to brief the same.

Thanks for your co-operation.

@shanmu

My connection is established & later disconnected with following error message. This message comes when I send a ping. My pings are a simple text message with word ping.

WS connection closed. Status [CloseStatus[code=1003, reason=Client messages not supported]]

So, it seems this is the cause. Please give me the exact format of the heartbeat message.

@shanmu

I have just looked at the upstox pro website & it uses following json format for hearbeat:

{
  "type": "subscribe",
  "messageType": "heartbeat"
}

Questions:

  1. Does a client need to send a ping (this is most common) or your server sends a ping & client needs to respond with a pong?
  2. What is the heartbeat message format on your api (like the one I have shown for your Upstox website)?

@priteshmhatre

Our WebSocket server sends out ping events, expecting a corresponding pong response. Most WebSocket clients across various programming languages handle this automatically. If you choose to customize the default behavior, you should ensure your client listens for pings and sends back pongs accordingly.

We accept any general payload with the pong response and do not require a specific format.

Thank you!

@shanmu

Mention the format in docs that you use standard ping frame. If you go through the docs of other brokers, many are using different formats for hearbeat ping/pong. So, users of the api who have worked across different brokers would be looking for this information.

Please close the ticket.