Unable to get data via Refintiv Data Library (refinitiv.data) Python
Hi, it looks like I'm unable to retrieve any data via Refinitiv using the new Refinitiv Data Library.
Sample Code:
import os
os.environ["RD_LIB_CONFIG_PATH"] = "../../Configuration"
import refinitiv.data as rd
rd.open_session()
Code is fine up to here, (desktop) session seems to be successfully opened:
However, attempting to get the data as demonstrated in the examples does not seem to work:
rd.get_data(['LSEG.L', 'VOD.L'])
Would appreciate any help, thanks.
Best Answer
-
You can enable trace in the Python WebSocket, as shown below.
websocket.enableTrace(True)
print("Connecting to WebSocket " + url + " ...")
web_socket_app = websocket.WebSocketApp(url, header=headers,
on_message=on_message,
on_error=on_error,
on_close=on_close,
subprotocols=['tr_json2'])The output looks like this:
Otherwise, you can test the WebSocket connection with the Curl command.
curl --include --no-buffer --header "Connection: Upgrade" --header "Upgrade: websocket" --header "Host: localhost:9060" --header "Origin: http://localhost:9060" --header "Sec-WebSocket-Key: 4FlPV2h/xF20YXwlt7zBiw==" --header "Sec-WebSocket-Version: 13" --header "x-tr-applicationid: <app key>" --header "Sec-WebSocket-Protocol: tr_json2" -v http://localhost:9060/api/rdp/streaming/pricing/v1/WebSocket
The output looks like this:
Please make sure that 9060 is the correct port by accessing this URL (http://localhost:9060/api/status) via a web browser.
0
Answers
-
Thanks for reaching out to us.
I can run it properly.
[stream_connection] - [_run_websocket_listener] - [OMMSTREAMING_PRICING_0.0] connect
num_attempt : 0
url : ws://localhost:9060/api/rdp/streaming/pricing/v1/WebSocket
headers : ['User-Agent: Python', 'x-tr-applicationid: <application id>', 'Authorization: Bearer <token>']
cookies : None
transport : websocket
subprotocols: ['tr_json2']
[2023-01-06 12:07:19,216] - [sessions.desktop.workspace.0] - [DEBUG] - [112488 - ThreadOMMSTREAMING_PRICING_0.0] - [stream_connection] - [_on_ws_open] - [OMMSTREAMING_PRICING_0.0] on_ws_openPlease share the full Refinitiv Data log when the problem occurred. I would like to verify the version of the RD library and dependencies.
You can also run the following code to test the connection.
import websocket
import threading
import time
url = "ws://localhost:9060/api/rdp/streaming/pricing/v1/WebSocket"
application_id = "x-tr-applicationid: <application id>"
token = "Authorization: Bearer <token>"
headers = ['User-Agent: Python',application_id,token]
def on_message(ws, message):
print("on message")
def on_error(ws, error):
""" Called when websocket error has occurred """
print(error)
def on_close(ws, close_status_code, close_msg):
""" Called when websocket is closed """
print("WebSocket Closed")
def on_open(ws):
""" Called when handshake is complete and websocket is open, send login """
print("WebSocket successfully connected!")
# Start websocket handshake
print("Connecting to WebSocket " + url + " ...")
web_socket_app = websocket.WebSocketApp(url, header=headers,
on_message=on_message,
on_error=on_error,
on_close=on_close,
subprotocols=['tr_json2'])
web_socket_app.on_open = on_open
# Event loop
wst = threading.Thread(target=web_socket_app.run_forever)
wst.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
web_socket_app.close()You can the url, <application id>, and <token> from the Refinitiv Data log.
The output looks like this:
If this code is unable to establish a websocket connection, the problem could be from network settings.
0 -
Hi Jiraponse,
Thanks - comparing the headers between yours and mine its clear that I do not have a token, and only have an application ID.
My understanding is that the application ID is the App Key from the Eikon desktop application, what is the application ID here then?
Thanks.
Wesley
0 -
Yes, it is an application key.
You can remove token from the headers.
headers = ['User-Agent: Python',application_id]
Please verify the versoin of the RD library that you are using.
I am using the latest one (RD version is 1.0.0).
0 -
Hi Jirapongse,
With default company proxy settings:
Explicitly setting proxy to None:
Is there a way to troubleshoot the network settings?
My version of RD library is 1.0.0b25.
0 -
Hi Jirapongse, the port is correct.
Output 1 with default proxy settings:
-----------------------
--- response header ---
HTTP/1.1 200 Connection established
-----------------------
--- request header ---
GET /api/rdp/streaming/pricing/v1/WebSocket HTTP/1.1
Upgrade: websocket
Host: localhost:9060
Origin: http://localhost:9060
Sec-WebSocket-Key: E6cohDP/n2dJqMYLNwX++w==
Sec-WebSocket-Version: 13
Connection: Upgrade
Sec-WebSocket-Protocol: tr_json2
User-Agent: Python
x-tr-applicationid: <id>
-----------------------
--- response header ---
HTTP/1.1 301 Moved Permanently Server: BlueCoat-Security-Appliance
Location:http://10.190.169.68
Connection: Close
-----------------------
Connecting to WebSocket ws://localhost:9060/api/rdp/streaming/pricing/v1/WebSocket ...
scheme http is invalid
WebSocket ClosedIs this a firewall issue?
0 -
Yes, it is possible.
I found that BlueCoat-Security-Appliance relates to the secure web gateway application.
0 -
Hi Jirapongse,
On removing the proxies, I get the following returned:
--- request header ---
Connecting to WebSocket ws://localhost:9060/api/rdp/streaming/pricing/v1/WebSocket ...
GET /api/rdp/streaming/pricing/v1/WebSocket HTTP/1.1
Upgrade: websocket Host: localhost:9060 Origin: http://localhost:9060
Sec-WebSocket-Key: Nb8WlSx9JHid4fxn8LM4iQ==
Sec-WebSocket-Version: 13
Connection: Upgrade
Sec-WebSocket-Protocol: tr_json2
User-Agent: Python
x-tr-applicationid: <key>
-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: x2LKwD6zgl3oUV+6z+WhBHBwxCw=
Sec-WebSocket-Protocol: tr_json2
-----------------------
WebSocket successfully connected!Thanks.
EDIT: It works now, I just don't have the credentials at the moment and am in touch with the account manager. Thanks!
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 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
- 367 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
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛