how to subscribe to more rics on demand on websocket in Python

I’m now trying to subscribe several rics but the it seems once I subscribe to a ric, I cannot subscribe to another:
RECEIVED on session1:
[
{
"ID":2,
"Key":{
"Name":"/0005.HK",
"Service":"ELEKTRON_DD"
},
"State":{
"Code":"AlreadyOpen",
"Data":"Suspect",
"Stream":"Closed",
"Text":"Request Rejected: Cannot request new item on open stream."
},
"Type":"Status"
}
]
I did see in the docs where we can send a list of rics in batch. However, I’d like to append new ric on demand instead of subscribe all in one go.
what i am doing currently (which i believe is incorrect):
session1 = WebSocketTestSession("session1", hostList[0], sts_token, position)
session1.connect()
if session1.logged_in:
session1._send_market_price_request('/TRI.N')
session1._send_market_price_request('/0005.HK')
session1._send_market_price_request('/0700.HK')
Best Answer
-
Hi @daniel.yuen
Please work through the tutorials before you start coding your application - starting from the first relevant 'Connect to' tutorial i.e.
Connect to Refinitiv Real-Time - Optimized (cloud connection)
OR
Connect to RTDS (deployed ADS connection)
Working through the tutorials will make things much clearer and hopefully save you time in the long run.
For example, the above tutorials will show you that you should use StreamID:1 for the Login request.
I don't see your code for the Login request, but I suspect you are using 0 or 1 for the Login streamID and then closing the stream when you call _send_close_stream_request with the Login StreamID. When you close the Login Stream - you are logging out and closing the connection.
Also, if you are not interested in streaming data and only want to snapshot the current price for an instrument, you can use the Snapshot feature which will request the instrument and close the stream once you receive the price - saving you the effort of closing the stream.
e.,g.
{
"ID":2,
"Key":{
"Name":"VOD.L"
},
"Streaming":false
}0
Answers
-
Hi @daniel.yuen
You need to use a unique Stream ID for each new item you open a stream for. So, you need to keep a StreamID counter or something similar which you can increment etc.
Once you close a stream you can re-use a StreamID if required.
See the Request Data Tutorial for details on StreamID.
0 -
You can see that after I subscribed to the first one it worked. then after I subscribed to the 2nd "0700.HK' i received message "
WebSocket Closed for session1" despite with a different ID. I also tried close the first connection first (calling _sending_close_stream_request) but it did not help.
Log messages
RECEIVED on session1:
SENT on session1:
{
"ID":0,
"Key":{
"Name":"/0005.HK",
"Service":"ELEKTRON_DD"
}
}
RECEIVED on session1:
20210511 13:47:44 - /0005.HK: 48.6/48.65, 49.15/49.2
RECEIVED on session1:
20210511 13:47:51 - /0005.HK: 48.6/48.65, 0/0
RECEIVED on session1:
RECEIVED on session1:
SENT on session1:
{
"Type":"Pong"
}
RECEIVED on session1:
RECEIVED on session1:
RECEIVED on session1:
RECEIVED on session1:
SENT on session1:
{
"Type":"Pong"
}
RECEIVED on session1:
20210511 13:48:30 - /0005.HK: 48.6/48.65, 0/0
RECEIVED on session1:
RECEIVED on session1:
RECEIVED on session1:
RECEIVED on session1:
RECEIVED on session1:
SENT on session1:
{
"Type":"Pong"
}
RECEIVED on session1:
SENT on session1:
{
"ID":0,
"Type":"Close"
}
SENT on session1:
{
"ID":1,
"Key":{
"Name":"/0700.HK",
"Service":"ELEKTRON_DD"
}
}
WebSocket Closed for session1
Reconnect to the endpoint for session1 after 3 seconds...
Connecting to WebSocket wss://amer-3-t2.streaming-pricing-api.refinitiv.com:443/WebSocket for session1...
WebSocket successfully connected for session1!
Codes Snippets
session1 = WebSocketTestSession("session1", hostList[0], sts_token, position)
session1.connect()
time.sleep(8)
if session1.logged_in:
# session1._send_market_price_request('/TRI.N')
session1._send_market_price_request('/0005.HK')
#
time.sleep(60)
session1._send_close_stream_request(0)
if session1.logged_in:
session1._send_market_price_request('/0700.HK')def _send_market_price_request(self, ric_name):
""" Create and send simple Market Price request """
mp_req_json = {
'ID': self.subscription_count,
'Key': {
'Name': ric_name,
'Service': service
},
}
self.subscription_count += 1
self.web_socket_app.send(json.dumps(mp_req_json))
print("SENT on " + self.session_name + ":")
print(json.dumps(mp_req_json, sort_keys=True, indent=2, separators=(',', ':')))
def _send_close_stream_request(self, stream_id):
""" Create and send simple Market Price request """
mp_req_json = {
'ID': stream_id,
'Type': 'Close',
}
self.web_socket_app.send(json.dumps(mp_req_json))
print("SENT on " + self.session_name + ":")
print(json.dumps(mp_req_json, sort_keys=True, indent=2, separators=(',', ':')))0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 690 Datastream
- 1.4K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 559 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 24 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 279 Open PermID
- 45 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 713 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛