question

Upvotes
Accepted
10 3 1 3

How to send keealive for python websocket api

I have a python websocket listening to streaming data from TREP server which disconnect roughly every half minutes which seems indicates the connection is cut by server periodically, is there any keepalive message that I have to send to TREP server to avoid this? thanks

elektronrefinitiv-realtimetrepwebsockets
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Here is part the request I sent (I cannot send a full list of rics because the comment length limit):

{"Domain":"MarketPrice","ID":-500000,"Key":{"Name":["GBRPIZ7Y=","CAD="],"Service":"IDN_SELECTFEED"},"Priority":{"Class":1,"Count":1},"Streaming":true,"Type":"Request"}

Hello @lzhuang1

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?

If yes, please click the 'Accept' text next to the reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question.

Thanks,

AHS

Upvotes
Accepted
9.5k 10 5 7

Hello @lzhuang1

Your applications must be prepared to respond with a Pong message whenever they receive a Ping message from ADS(one component of TREP). Otherwise, the ADS will disconnect the application after PingTimeout which you can find in Login response. For more details, please refer to Ping and Pong web socket API document

The snipped example source code:

For the complete source source code, please refer to market_price.py in WebSocket API Sample Applications which can be downloaded from Download of WebSocket API.


sendpong.png (17.5 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

@pimchaya, thanks for your response.

Yes I followed the example and that's what I did in my code, and I use websock-client 0.56.0 to connect the websocket api. The periodical disconnection decision seems from server side because the error shows "Connection is already closed" when my script is still listening

Upvotes
7.6k 15 6 9

@lzhuang1

Not sure that Did you received ping message from ADS? and Have you sent pong back?

Ping and Pong messages are exchanged between endpoints of a connection to verify that the remote endpoint is still alive. The ADS will send Ping messages to applications when it does not receive traffic for a while, so applications must be prepared to respond with a Pong message whenever they receive a Ping.

The ADS includes an informational PingTimeout element in its Login response, indicating the time (in seconds) after which the ADS will disconnect the application if it receives no traffic in response to a sent Ping.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
13k 32 12 18

Hi @lzhuang1, before we go on investigating the protocol and ADS logs, can you please run the Python Websocket sample - market_price.py, included in the Websocket SDK, and confirm that this happens with the official sample as well?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Yes that's what did, I copy the script and the only thing I change is the login, app_id and the request. The request contains 359 RICs for streaming data. I cannot paste the RICs here because the comment size limit, let me know if I can reach out you and I can send them to you maybe

Can you please upload your complete code here. You can remove the credentials from the file, and we will test it with ADS here. Use "Upload File" button.

Click below to post an Idea Post Idea