I am currently trying to retrieve streaming news for RDP platform.
When I run the following code in a jupyter notebook cell all is working fine :
import refinitiv.dataplatform as rdp import datetime import zlib import base64 import json APP_KEY = '***' MACHINE_ID = '***' PASSWD = '***' rdp.open_platform_session(app_key=APP_KEY, grant=rdp.GrantPassword(username=MACHINE_ID, password=PASSWD) ) item_stream = rdp.ItemStream(session=rdp.get_default_session(), domain=DOMAIN, name=NAME, #should be optional on_refresh = lambda item_stream, event : processMRNstart("Refresh", event), on_update = lambda item_stream, event : processMRNUpdate("Update", event), on_status = lambda item_stream, event : processMRNstart("Status", event), on_complete = lambda item_stream : processMRNstart("Complete", "") ) item_stream.open()
However, when I copy paste this code into a python script .py and run in into the command shell it stucks around the rpd.open_platform_session function and nothing happens.
Any ideas about the different behavior between Jupyter notebook and Python scripts for getteting streaming news from RDP platform ?
I suspect what is happening. Try the following, let us know how this works for you:
import refinitiv.dataplatform as rdp import datetime import zlib import base64 import json import time app_key = 'YOURKEY' user = 'YOURUSER' password = 'YOURPASSWORD' rdp.open_platform_session(app_key=app_key, grant=rdp.GrantPassword(username=user, password=password) ) item_stream = rdp.ItemStream(session = rdp.get_default_session(), name = "EUR=", on_refresh = lambda s, msg : print(json.dumps(msg, indent=2)), on_update = lambda s, msg : print(json.dumps(msg, indent=2)), on_status = lambda s, msg : print(json.dumps(msg, indent=2))) item_stream.open() while True: time.sleep(0.2)
For me this code runs the same from jupyter notebook and from python script in command shell.
Are you finding the same version of python, with the same versions of the libraries installed, via jupiter python as you do via command shell?
To confirm, run from pybook and from shell:
I have tried the code with both Python Console and Jupyter Notebook. They can run and give the same result.
Did you run Notebook and Console on the same Python environment as suggest by my colleague above?
Beside the Python version, you also need to same libraries (and versions) as well. You can use the following commands to list the installed libraries
Thank you for your quick answer.
In fact, I use exactly the same environment between shell and jupyter notebook (same python version and same libraries versions).
I switch from a windows environement in which I launched my python script from the powershell to a linux environment and the connexion now works (the status is displayed as open). However, in the python script I print and write the incoming streaming news. In jupyter notebook it is ok but from the shell (I run the following command python3 myscript.py) there is no print in the shell console nor anything written in the output file.
I have instanciated a logger to see what is happenning and it appears we get the status event ('status': <StreamState.Open: 3>) then the refresh event but the logs stop afterwards.
What is the best way to run scenario simulations on options using the RDP library? for a given listed option i would like to see the premium on a future date based on some vol and underlying price input.