Skip to content

Commit a3d4100

Browse files
committed
version b5 session related changes
1 parent 76f62bd commit a3d4100

11 files changed

+2410
-2443
lines changed

Tutorials/2.Content/2.2-Pricing/TUT_2.2.05-Pricing-StreamingChain.ipynb

Lines changed: 135 additions & 133 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,21 @@
11
# Refinitiv Data Platform Library for Python
2-
## Delivery - OMMItemStream - Market Price data via callback inside a Python Script
3-
4-
#This demonstrates how to use the OMM Item Stream interface to request streaming Quote and Trade data
5-
#via a Script as opposed to running in a Jupyter Notebook
2+
# This demonstrates how to use the content pricing interface to request streaming Quote and Trade data
3+
# via a Script as opposed to running in a Jupyter Notebook
64

5+
# As these tutorial Notebooks are categorised into sub-folders and to avoid the need for multiple config files, we will use the
6+
# _RD_LIB_CONFIG_PATH_ environment variable to point to a single instance of the config file in the
7+
# top-level ***Configuration*** folder.
8+
# Before proceeding, please **ensure you have entered your credentials** into the config file in the ***Configuration*** folder.
9+
import os
10+
os.environ["RD_LIB_CONFIG_PATH"] = "../../../Configuration"
711
import refinitiv.data as rd
8-
from refinitiv.data._data.legacy import get_default_session, set_default_session
9-
from refinitiv.data.delivery import endpoint_request
1012
import datetime
1113
import json
1214
import time
13-
import logging.config
14-
import configparser as cp
1515
import asyncio
16-
import os
17-
from dotenv import load_dotenv
18-
19-
# load credentials from a .env file (+ override any OS system env vars of the same name)
20-
load_dotenv(dotenv_path='c:/Refinitiv/.env',override=True)
21-
22-
23-
APP_KEY = os.environ['APP_KEY'] # 'YOUR APP_KEY'
24-
RDP_LOGIN = os.environ['RDP_LOGIN'] # 'YOUR REFINITIV DATA PLATFORM_LOGIN' e.g. 'GE-A-01234567-8-9101'
25-
RDP_PASSWORD = os.environ['RDP_PASSWORD'] # 'YOUR REFINITIV DATA PLATFORM PASSWORD' (the long password)
26-
DEPLOYED_PLATFORM_HOST = os.getenv('DEPLOYED_PLATFORM_HOST') # YOUR DEPLOYED SERVER:PORT e.g. 'myADS:15000'
27-
DEPLOYED_PLATFORM_USER_NAME = os.getenv('DEPLOYED_PLATFORM_USER_NAME') # YOUR DACS user name
2816

29-
30-
# Some Global variables
31-
session=None # Our session
32-
33-
# Run for 60 seconds
34-
exit_time = time.time() + 60
35-
36-
37-
def open_session(session_type=None):
38-
session = get_default_session()
39-
if session is None:
40-
if session_type == "desktop":
41-
session = rd.session.desktop.Definition(APP_KEY).get_session()
42-
elif session_type == "rdp":
43-
session = rd.session.platform.Definition(
44-
app_key=APP_KEY,
45-
grant=rd.session.platform.GrantPassword(
46-
username=RDP_LOGIN,
47-
password=RDP_PASSWORD
48-
)
49-
).get_session()
50-
elif session_type == "deployed":
51-
session = rd.session.platform.Definition(
52-
app_key=APP_KEY,
53-
deployed_platform_host = DEPLOYED_PLATFORM_HOST,
54-
deployed_platform_username = DEPLOYED_PLATFORM_USER_NAME
55-
).get_session()
56-
57-
if session is None:
58-
raise Exception(f"Wrong session_type: {session_type}. It must be ['desktop', 'rdp', 'deployed']")
59-
else:
60-
#session.set_log_level(logging.DEBUG)
61-
session.set_log_level(logging.WARNING)
62-
set_default_session(session)
63-
session.open()
64-
return session
65-
66-
def close_session():
67-
session = get_default_session()
68-
if session:
69-
session.close()
17+
# Run the example for 30 seconds
18+
exit_time = time.time() + 30
7019

7120
# Callback function to display data or status events
7221
# Function to handle the intial Refresh for each item
@@ -88,7 +37,7 @@ def handle_status(streaming_prices, instrument_name, status):
8837
# Our main code section
8938

9039
# Open a session using the helper functions in the above Credentials section
91-
open_session('rdp')
40+
rd.open_session()
9241

9342
# Define our Streaming Price object
9443
streams = rd.content.pricing.Definition(
@@ -114,4 +63,4 @@ def handle_status(streaming_prices, instrument_name, status):
11463
asyncio.get_event_loop().run_until_complete(asyncio.sleep(1))
11564

11665
streams.close()
117-
close_session()
66+
rd.close_session()

Tutorials/2.Content/2.2-Pricing/TUT_2.2.06-Pricing-StreamingEventsDF.ipynb

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,49 @@
1616
"cell_type": "markdown",
1717
"metadata": {},
1818
"source": [
19-
"## Import the library and load credentials\n",
19+
"## Set the location of the configuration file\n",
20+
"For ease of use, you can set various initialization parameters of the RD Library in the **_refinitiv-data.config.json_** configuration file - as described in the Quick Start -> Sessions example.\n",
2021
"\n",
21-
"Credentials used by this and the other tutorials notebooks are stored in the **Configuration/credentials.ipynb** file. \n",
22+
"### One config file for the tutorials\n",
23+
"As these tutorial Notebooks are categorised into sub-folders and to avoid the need for multiple config files, we will use the _RD_LIB_CONFIG_PATH_ environment variable to point to a single instance of the config file in the top-level ***Configuration*** folder.\n",
2224
"\n",
23-
"You should have edited the **Configuration/credentials.ipynb** to set your credentials as part of the **Quick Start** step."
25+
"Before proceeding, please **ensure you have entered your credentials** into the config file in the ***Configuration*** folder."
2426
]
2527
},
2628
{
2729
"cell_type": "code",
2830
"execution_count": 1,
29-
"metadata": {
30-
"collapsed": false,
31-
"jupyter": {
32-
"outputs_hidden": false
33-
},
34-
"pycharm": {
35-
"name": "#%%\n"
36-
}
37-
},
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"import os\n",
35+
"os.environ[\"RD_LIB_CONFIG_PATH\"] = \"../../../Configuration\""
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 2,
41+
"metadata": {},
3842
"outputs": [],
3943
"source": [
4044
"from refinitiv.data.content import pricing\n",
45+
"import refinitiv.data as rd\n",
4146
"from pandas import DataFrame\n",
42-
"from IPython.display import display, clear_output\n",
43-
"\n",
44-
"%run ../../Configuration/credentials.ipynb"
47+
"from IPython.display import display, clear_output"
4548
]
4649
},
4750
{
4851
"cell_type": "markdown",
4952
"metadata": {},
5053
"source": [
51-
"## Open the session of your choice\n",
54+
"## Open the default session\n",
5255
"\n",
53-
"Use our helper function in the Credentials notebook, **open_session(session_type)**, to create and open a session to connect to the \n",
54-
"- Refinitiv Data Platform directly (session_type=\"rdp\") or via \n",
55-
"- Eikon 4 or Refinitiv Workspace (session_type=\"desktop\") or via a \n",
56-
"- local realtime infrastructure (session_type=\"deployed\").\n",
57-
"\n",
58-
"You can also set a default in the **credentials** notebook - which I have done, and so I don't need to specify a session_type:"
56+
"To open the default session ensure you have a '*refinitiv-data.config.json*' in the ***Configuration*** directory, populated with your credentials and specified a 'default' session in the config file \n"
5957
]
6058
},
6159
{
6260
"cell_type": "code",
63-
"execution_count": 2,
61+
"execution_count": 3,
6462
"metadata": {
6563
"collapsed": false,
6664
"jupyter": {
@@ -74,17 +72,16 @@
7472
{
7573
"data": {
7674
"text/plain": [
77-
"<refinitiv.data.session._platform_session.Definition object at 0x2666dcd7790 {session_name='default-session'}>"
75+
"<refinitiv.data.session.platform.Definition object at 0x173dd8b9520 {session_name='rdp'}>"
7876
]
7977
},
80-
"execution_count": 2,
78+
"execution_count": 3,
8179
"metadata": {},
8280
"output_type": "execute_result"
8381
}
8482
],
8583
"source": [
86-
"# I have defined a default Session type in the Credentials notebook - so no need to specify it here\n",
87-
"open_session()"
84+
"rd.open_session()"
8885
]
8986
},
9087
{
@@ -96,7 +93,7 @@
9693
},
9794
{
9895
"cell_type": "code",
99-
"execution_count": 3,
96+
"execution_count": 4,
10097
"metadata": {},
10198
"outputs": [],
10299
"source": [
@@ -134,7 +131,7 @@
134131
},
135132
{
136133
"cell_type": "code",
137-
"execution_count": 4,
134+
"execution_count": 5,
138135
"metadata": {},
139136
"outputs": [
140137
{
@@ -165,34 +162,34 @@
165162
" <tbody>\n",
166163
" <tr>\n",
167164
" <th>EUR=</th>\n",
168-
" <td>1.1786</td>\n",
169-
" <td>1.179</td>\n",
165+
" <td>1.1294</td>\n",
166+
" <td>1.1297</td>\n",
170167
" </tr>\n",
171168
" <tr>\n",
172169
" <th>GBP=</th>\n",
173-
" <td>1.3833</td>\n",
174-
" <td>1.3838</td>\n",
170+
" <td>1.3337</td>\n",
171+
" <td>1.334</td>\n",
175172
" </tr>\n",
176173
" <tr>\n",
177174
" <th>JPY=</th>\n",
178-
" <td>110.04</td>\n",
179-
" <td>110.06</td>\n",
175+
" <td>113.87</td>\n",
176+
" <td>113.88</td>\n",
180177
" </tr>\n",
181178
" <tr>\n",
182179
" <th>CAD=</th>\n",
183-
" <td>1.2655</td>\n",
184-
" <td>1.2659</td>\n",
180+
" <td>1.2761</td>\n",
181+
" <td>1.2765</td>\n",
185182
" </tr>\n",
186183
" </tbody>\n",
187184
"</table>\n",
188185
"</div>"
189186
],
190187
"text/plain": [
191188
" BID ASK\n",
192-
"EUR= 1.1786 1.179\n",
193-
"GBP= 1.3833 1.3838\n",
194-
"JPY= 110.04 110.06\n",
195-
"CAD= 1.2655 1.2659"
189+
"EUR= 1.1294 1.1297\n",
190+
"GBP= 1.3337 1.334\n",
191+
"JPY= 113.87 113.88\n",
192+
"CAD= 1.2761 1.2765"
196193
]
197194
},
198195
"metadata": {},
@@ -224,16 +221,16 @@
224221
},
225222
{
226223
"cell_type": "code",
227-
"execution_count": 5,
224+
"execution_count": 6,
228225
"metadata": {},
229226
"outputs": [
230227
{
231228
"data": {
232229
"text/plain": [
233-
"<StreamState.Closed: 1>"
230+
"<OpenState.Closed: 3>"
234231
]
235232
},
236-
"execution_count": 5,
233+
"execution_count": 6,
237234
"metadata": {},
238235
"output_type": "execute_result"
239236
}
@@ -251,11 +248,11 @@
251248
},
252249
{
253250
"cell_type": "code",
254-
"execution_count": 6,
251+
"execution_count": 7,
255252
"metadata": {},
256253
"outputs": [],
257254
"source": [
258-
"close_session()"
255+
"rd.close_session()"
259256
]
260257
},
261258
{

0 commit comments

Comments
 (0)