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
Best Answer
-
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.
0
Answers
-
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"}
0 -
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.
0 -
@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
0 -
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?
0 -
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
0 -
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.
0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 162 App Studio
- 4 Block Chain
- 5 Bot Platform
- 17 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 370 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛