Skip to content

Commit 56002c7

Browse files
authored
Add files via upload
1 parent 68fc4bd commit 56002c7

File tree

1 file changed

+285
-1
lines changed

1 file changed

+285
-1
lines changed
Lines changed: 285 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,285 @@
1-
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "77a0683d",
6+
"metadata": {},
7+
"source": [
8+
"# Refinitiv Data Platform Library for Python\n",
9+
"## Define and Open a session\n",
10+
"\n",
11+
"Depending on the Credentials and Refinitiv Products/Services you have access to, you need define & open either a PlatformSession or DesktopSession: \n",
12+
"\n",
13+
" - **PlatformSession:** Used to connect to the Refinitiv Data Platform (RDP) directly or via a local (deployed) Real-time Distribution System(RTDS). The PlatformSession requires RDP credentials (machine account) or connection details of your local platform (IP of the local server and DACS user name).\n",
14+
" - When the PlatformSession is used with RDP credentials only, it retrieves both streaming data and non-streaming data from the Refinitiv Data Platform.\n",
15+
" - When the PlatformSession is used with connection details of your local deployed platform, it retrieves streaming data only from your local platform. \n",
16+
" \n",
17+
" \n",
18+
" - **DesktopSession:** This type of session is used to connect RDP either via Eikon or via the Refinitiv Workspace. Eikon or the Refinitiv Workspace must be run **on the same PC** as your Python code.\n",
19+
" \n",
20+
"You will also require an App Key that uniquely identifies your application. Please refer to the Refinitiv Data Libraries Quick Start guide's **Access Credentials** section for instructions on creating an App Key."
21+
]
22+
},
23+
{
24+
"cell_type": "markdown",
25+
"id": "435ee2f6",
26+
"metadata": {},
27+
"source": [
28+
"## Import the library and load credentials\n",
29+
"\n",
30+
"Credentials used by this and the other tutorials notebooks are stored in the **Configuration//credentials.ipynb** file. \n",
31+
"\n",
32+
"Please edit **Configuration/credentials.ipynb** to set your credentials and run the next cell to continue"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"id": "3ac59b42",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"import refinitiv.data as rd\n",
43+
"\n",
44+
"%run ../Configuration/credentials.ipynb"
45+
]
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"id": "ed69a14d",
50+
"metadata": {},
51+
"source": [
52+
"## Define the session of your choice"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"id": "b678f53f",
58+
"metadata": {},
59+
"source": [
60+
"#### Desktop Session\n",
61+
"\n",
62+
"Create and open a Desktop session to connect to the Refinitiv Data Platform pvia Eikon 4 or the Refinitiv Workspace."
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": null,
68+
"id": "293e44eb",
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"session = rd.session.desktop.Definition(APP_KEY).get_session()"
73+
]
74+
},
75+
{
76+
"cell_type": "markdown",
77+
"id": "f8427153",
78+
"metadata": {},
79+
"source": [
80+
"#### OR Platform Session\n",
81+
"Create and open a Platform session to connect directly to the Refinitiv Data Platform. "
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"id": "856e52b5",
88+
"metadata": {},
89+
"outputs": [],
90+
"source": [
91+
"session = rd.session.platform.Definition(\n",
92+
" APP_KEY, \n",
93+
" rd.session.platform.GrantPassword(\n",
94+
" username = RDP_LOGIN, \n",
95+
" password = RDP_PASSWORD\n",
96+
" )\n",
97+
").get_session()"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"id": "5f8f8320",
103+
"metadata": {},
104+
"source": [
105+
"#### OR Local(Deployed) Session\n",
106+
"Create and open a Platform session to connect to a local (deployed) real-time distribution system(RTDS). "
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"id": "99fe0ff1",
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"session = rd.session.platform.Definition(\n",
117+
" APP_KEY, \n",
118+
" deployed_platform_host = DEPLOYED_PLATFORM_HOST,\n",
119+
" deployed_platform_username = DEPLOYED_PLATFORM_USER_NAME\n",
120+
").get_session()"
121+
]
122+
},
123+
{
124+
"cell_type": "markdown",
125+
"id": "48f1ee72",
126+
"metadata": {},
127+
"source": [
128+
"#### OR Local + Platform\n",
129+
"\n",
130+
"Create and open a Platform session to connect to both the Data Platform and a local (deployed) real-time distribution system (RTDS). \n",
131+
"With this configuration, streaming data is retrieved from the local platform while non-streaming data is retrieved from the Refinitiv Data Platform. \n",
132+
"This scenario could apply where you want to consume both internally published streaming data and non-streaming data from Refinitiv"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"id": "c0786401",
139+
"metadata": {},
140+
"outputs": [],
141+
"source": [
142+
"session = rd.session.platform.Definition(\n",
143+
" APP_KEY, \n",
144+
" grant = rd.session.platform.GrantPassword(\n",
145+
" username = RDP_LOGIN, \n",
146+
" password = RDP_PASSWORD\n",
147+
" ),\n",
148+
" deployed_platform_host = DEPLOYED_PLATFORM_HOST,\n",
149+
" deployed_platform_username = DEPLOYED_PLATFORM_USER_NAME\n",
150+
").get_session()"
151+
]
152+
},
153+
{
154+
"cell_type": "markdown",
155+
"id": "7e0ca71f",
156+
"metadata": {},
157+
"source": [
158+
"## Then open it"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"id": "edda7d30",
165+
"metadata": {},
166+
"outputs": [],
167+
"source": [
168+
"session.open()"
169+
]
170+
},
171+
{
172+
"cell_type": "markdown",
173+
"id": "616f4b4d",
174+
"metadata": {},
175+
"source": [
176+
"## Diagnose any Session issues\n",
177+
"If you cannot open a session, to generate addtional logging, enable DEBUG logging and call session.open() again"
178+
]
179+
},
180+
{
181+
"cell_type": "code",
182+
"execution_count": null,
183+
"id": "be274afd",
184+
"metadata": {},
185+
"outputs": [],
186+
"source": [
187+
"import logging.config\n",
188+
"session.set_log_level(logging.DEBUG)\n",
189+
"session.open()\n",
190+
"# To set logging back to default value\n",
191+
"session.set_log_level(logging.WARNING)"
192+
]
193+
},
194+
{
195+
"cell_type": "markdown",
196+
"id": "73e7ef7f",
197+
"metadata": {},
198+
"source": [
199+
"## Close the session"
200+
]
201+
},
202+
{
203+
"cell_type": "code",
204+
"execution_count": null,
205+
"id": "ac74a561",
206+
"metadata": {},
207+
"outputs": [],
208+
"source": [
209+
"session.close()"
210+
]
211+
},
212+
{
213+
"cell_type": "markdown",
214+
"id": "5ac7dc7b",
215+
"metadata": {},
216+
"source": [
217+
"## Session Events and State change notification\n",
218+
"If you want to be notified of any Session events or change in State you can optionally specify State and Event callbacks"
219+
]
220+
},
221+
{
222+
"cell_type": "code",
223+
"execution_count": null,
224+
"id": "e1467bc5",
225+
"metadata": {},
226+
"outputs": [],
227+
"source": [
228+
"# Callback to handle session state changes\n",
229+
"def on_state_cb(session, state_code, state_msg):\n",
230+
" print(f\"Session State:{state_code} | {state_msg}\")\n",
231+
"# Callback to handle session events\n",
232+
"def on_event_cb(session, event_code, event_msg):\n",
233+
" print(f\"Session event:{event_code} | {event_msg}\")\n",
234+
"\n",
235+
"# Using PlatformSession - can be applied to DesktopSession as well\n",
236+
"session = rd.session.platform.Definition(\n",
237+
" APP_KEY, \n",
238+
" rd.session.platform.GrantPassword(\n",
239+
" username = RDP_LOGIN, \n",
240+
" password = RDP_PASSWORD\n",
241+
" ),\n",
242+
" on_state=on_state_cb, on_event=on_event_cb\n",
243+
").get_session()\n",
244+
" \n",
245+
"session.open()\n",
246+
"\n",
247+
"#\n",
248+
"# Run your application code\n",
249+
"#\n",
250+
"\n",
251+
"# close the session when done\n",
252+
"session.close()"
253+
]
254+
},
255+
{
256+
"cell_type": "code",
257+
"execution_count": null,
258+
"id": "2b7068e0",
259+
"metadata": {},
260+
"outputs": [],
261+
"source": []
262+
}
263+
],
264+
"metadata": {
265+
"kernelspec": {
266+
"display_name": "RevData39",
267+
"language": "python",
268+
"name": "rd39"
269+
},
270+
"language_info": {
271+
"codemirror_mode": {
272+
"name": "ipython",
273+
"version": 3
274+
},
275+
"file_extension": ".py",
276+
"mimetype": "text/x-python",
277+
"name": "python",
278+
"nbconvert_exporter": "python",
279+
"pygments_lexer": "ipython3",
280+
"version": "3.9.4"
281+
}
282+
},
283+
"nbformat": 4,
284+
"nbformat_minor": 5
285+
}

0 commit comments

Comments
 (0)