Skip to content

Commit c3226ab

Browse files
committed
add dotenv, update libs and requirements files
1 parent 0947918 commit c3226ab

18 files changed

+1282
-1332
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#RKD Access Credentials
2+
RKD_USERNAME=<RKD Username>
3+
RKD_PASSWORD=<RKD Password>
4+
RKD_APP_ID=<RKD App ID>

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ notebook/.ipynb_checkpoints
77
*/.ipynb_checkpoints/*
88
trkd_websocketexample.py
99
ERT_in_Cloud/
10-
internal_dev/
10+
internal_dev/
11+
requirements.txt_old
12+
.env
13+
notebook/.env

README.md

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# RKD HTTP JSON with Python Example
2-
- version: 1.5.5
3-
- Last update: Oct 2021
1+
# RKD HTTP JSON with Python Examples
2+
- version: 1.6.0
3+
- Last update: Mar 2022
44
- Environment: Windows, Linux
55
- Compiler: Python
66
- Prerequisite: [Demo prerequisite](#prerequisite)
77

8+
Example Code Disclaimer:
9+
ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. REFINITIV MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF THE EXAMPLE CODE, OR THE INFORMATION, CONTENT, OR MATERIALS USED IN CONNECTION WITH THE EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF THE EXAMPLE CODE IS AT YOUR SOLE RISK.
10+
811
## <a id="overview"></a>Overview
912
The [Refinitiv Knowledge Direct (RKD) API](https://developers.refinitiv.com/en/api-catalog/refinitiv-knowledge-direct/refinitiv-knowledge-direct-api-rkd-api) (formerly known as TRKD API) integrates into your website, trading platform, company intranet/extranet, advisory portal and mobile applications to provide up-to-date financial market data, news and analytics and powerful investment tools.
1013

@@ -35,41 +38,71 @@ All source code and scripts are provided under the Apache 2.0 license. They are
3538

3639
## <a id="prerequisite"></a>Prerequisite
3740
The following softwares are required to use this script
38-
- RKD API credentials. Please reach out to your Refinitiv sales associate to acquire RKD access credentials.
39-
- [Python 3](https://www.python.org/).
40-
- The [requests](http://docs.python-requests.org/en/master/) library
41-
- The [websocket-client](https://pypi.org/project/websocket-client/) library (*version 0.49 or greater*, for trkd_wsstreaming.py application only)
42-
- The [python-dateutil](https://pypi.org/project/python-dateutil/) library (for trkd_wsstreaming.py application only)
43-
- The [classic Jupyter Notebook](https://jupyter.org/) runtime (for the Notebook example application)
41+
- RKD API credentials. Please reach out to your Refinitiv representative to acquire RKD access credentials.
42+
- Python [Anaconda](https://www.anaconda.com/distribution/) or [MiniConda](https://docs.conda.io/en/latest/miniconda.html) distribution/package manager.
43+
- The [JupyterLab](https://jupyter.org/) runtime (for the Notebook example application)
4444

4545
All scripts support Python 3 only and not compatible with Python 2.
4646

4747
*Note:*
4848
- You can install Jupyter Notebook on your local machine and then test the example on the machine. The alternate choice is a free Jupyter Notebook on cloud environment such as [Azure Notebook](https://notebooks.azure.com/) provided by Microsoft. You can find more details from [this tutorial](https://docs.microsoft.com/en-us/azure/notebooks/tutorial-create-run-jupyter-notebook). If you are not familiar with Jupyter Notebook, the following [tutorial](https://www.datacamp.com/community/tutorials/tutorial-jupyter-notebook) created by DataCamp may help.
4949

50-
## <a id="run_console"></a>How to run the script
51-
Run the script via the command line (or shell)
52-
```
53-
$>python <application>.py
54-
```
55-
56-
## <a id="library_install"></a>Optional - How to install libraries for console examples
57-
The best way is via the pip package management tool
58-
1. export <Python_folder>\Scripts to your OS PATH environment
59-
2. call pip command to install requests
60-
```
61-
$>pip install -r requirements.txt
62-
```
63-
3. If you are behind proxy, set the proxy first
64-
```
65-
export https_proxy="http://<proxy.server>:<port>"
66-
$>pip install -r requirements.txt
67-
```
68-
69-
*Note*: If you aim to use only RKD HTTP JSON services, you can just install requests library via a ```pip install requests``` command.
70-
71-
## <a id="run_notebook"></a>Optional - How to install libraries for notebook examples
72-
Please follow the [classic Jupyter Notebook installation guide](https://jupyter.org/install) page.
50+
51+
### <a id="python_example_run"></a>How to run the Python Console examples
52+
53+
1. Open Anaconda Prompt and go to the project's Python folder
54+
2. Run the following command in the Anaconda Prompt application to create a Conda environment named *RKD_Python* for the project.
55+
```
56+
(base) $>conda create --name RKD_Python python=3.9
57+
```
58+
3. Once the environment is created, activate a Conda environment named ```RKD_Python``` with this command in Anaconda Prompt.
59+
```
60+
(base) $>conda activate RKD_Python
61+
```
62+
4. Run the following command to the dependencies in the *RKD_Python* environment with a **requirements.txt** file.
63+
```
64+
(RKD_Python) $>pip install -r requirements.txt
65+
```
66+
5. Once the dependencies installation process success, Go to the project's Python folder. and create a file name ```.env``` with the following content.
67+
```
68+
#RKD Access Credentials
69+
RKD_USERNAME=<RKD Username>
70+
RKD_PASSWORD=<RKD Password>
71+
RKD_APP_ID=<RKD App ID>
72+
```
73+
6. Run the script via the command line (or shell)
74+
```
75+
(RKD_Python) $>python <application>.py
76+
```
77+
78+
### <a id="python_example_run"></a>How to run the Python Notebook examples
79+
80+
1. Open Anaconda Prompt and go to the project's Python folder
81+
2. Run the following command in the Anaconda Prompt application to create a Conda environment named *RKD_Python_Notebook* for the project.
82+
```
83+
(base) $>conda create --name RKD_Python_Notebook python=3.9
84+
```
85+
3. Once the environment is created, activate a Conda environment named ```RKD_Python_Notebook``` with this command in Anaconda Prompt.
86+
```
87+
(base) $>conda activate RKD_Python_Notebook
88+
```
89+
4. Run the following command to the dependencies in the *RKD_Python_Notebook* environment with a **requirements-notebook.txt** file.
90+
```
91+
(RKD_Python_Notebook) $>pip install -r requirements-notebook.txt
92+
```
93+
5. Once the dependencies installation process success, Go to the project's notebook folder. and create a file name ```.env``` with the following content.
94+
```
95+
#RKD Access Credentials
96+
RKD_USERNAME=<RKD Username>
97+
RKD_PASSWORD=<RKD Password>
98+
RKD_APP_ID=<RKD App ID>
99+
```
100+
6. Run the following command to start the Jupyter Lab application
101+
```
102+
(RKD_Python_Notebook) $>notebook>jupyter lab
103+
```
104+
105+
Please follow the [JupyterLab installation guide](https://jupyter.org/install) page.
73106
74107
## <a id="rdp"></a>RDP and Refinitiv Real-Time - Optimized
75108
@@ -129,16 +162,16 @@ For further details, please check out the following resources:
129162
- version 1.0.10: 9 Aug 2018
130163
- remove all ```is not None``` statements and make them a bit more **Pythonic**.
131164
- version 1.0.11: January 2019
132-
- Add trkd_wsstreaming.py application for TRKD Streaming service.
165+
- Add trkd_wsstreaming.py application for RKD Streaming service.
133166
- Add License.md file
134167
- version 1.0.12: March 2019
135168
- Change all scripts to print JSON message in beauty format.
136169
- version 1.5: July 2019
137-
- Add TRKD Authentication Jupyter Notebook.
170+
- Add RKD Authentication Jupyter Notebook.
138171
- version 1.5.1: July 2019
139-
- Add TRKD Interday and Intraday Jupyter Notebooks.
172+
- Add RKD Interday and Intraday Jupyter Notebooks.
140173
- version 1.5.2: October 2019
141-
- Update TRKD Interday and Intraday services operations.
174+
- Update RKD Interday and Intraday services operations.
142175
- version 1.5.3: May 2020
143176
- Update RDP and Refinitiv Real-Time - Optimized information.
144177
- version 1.5.4: June 2020
@@ -147,3 +180,7 @@ For further details, please check out the following resources:
147180
- version 1.5.5: May 2021
148181
- Re-branding Product names and URLs.
149182
- add trkd_wsstreaming.py Batch support.
183+
- version 1.6.0: Mar 2022
184+
- Add ```dotenv``` and Environment Variable for credentials
185+
- Update requirements.txt and requirements-notebook.txt files
186+
- Update libraries versions

notebook/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RKD_USERNAME=<RKD Username>
2+
RKD_PASSWORD=<RKD Password>
3+
RKD_APP_ID=<RKD App ID>

notebook/trkd_authentication.ipynb

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
5+
"metadata": {
6+
"tags": []
7+
},
68
"source": [
79
"# RKD HTTP JSON with Python Example: Authentication\n",
810
"\n",
@@ -21,32 +23,21 @@
2123
},
2224
{
2325
"cell_type": "code",
24-
"execution_count": null,
25-
"metadata": {},
26-
"outputs": [],
27-
"source": [
28-
"# #uncomment if you do not have requests installed\n",
29-
"\n",
30-
"# # Install requests package in a current Jupyter kernal\n",
31-
"# import sys\n",
32-
"# !{sys.executable} -m pip install requests"
33-
]
34-
},
35-
{
36-
"cell_type": "code",
37-
"execution_count": null,
26+
"execution_count": 1,
3827
"metadata": {},
3928
"outputs": [],
4029
"source": [
4130
"# import requires libraries for HTTP Request and JSON Operation\n",
4231
"\n",
32+
"import os\n",
4333
"import requests\n",
44-
"import json"
34+
"import json\n",
35+
"from dotenv import load_dotenv"
4536
]
4637
},
4738
{
4839
"cell_type": "code",
49-
"execution_count": null,
40+
"execution_count": 2,
5041
"metadata": {},
5142
"outputs": [],
5243
"source": [
@@ -65,7 +56,16 @@
6556
"cell_type": "markdown",
6657
"metadata": {},
6758
"source": [
68-
"## main process"
59+
"## main process\n",
60+
"\n",
61+
"You should save a text file with **filename** `.env` or Environment Variables having the following configurations:\n",
62+
"\n",
63+
"```\n",
64+
"#RKD Access Credentials\n",
65+
"RKD_USERNAME=<RKD Username>\n",
66+
"RKD_PASSWORD=<RKD Password>\n",
67+
"RKD_APP_ID=<RKD App ID>\n",
68+
"```"
6969
]
7070
},
7171
{
@@ -74,16 +74,19 @@
7474
"metadata": {},
7575
"outputs": [],
7676
"source": [
77+
"%load_ext dotenv\n",
78+
"%dotenv\n",
79+
"\n",
7780
"# Input your RKD credentials here\n",
7881
"\n",
79-
"username = ''\n",
80-
"password = ''\n",
81-
"appid = ''"
82+
"username = os.getenv('RKD_USERNAME')\n",
83+
"password = os.getenv('RKD_PASSWORD')\n",
84+
"appid = os.getenv('RKD_APP_ID')"
8285
]
8386
},
8487
{
8588
"cell_type": "code",
86-
"execution_count": null,
89+
"execution_count": 5,
8790
"metadata": {},
8891
"outputs": [],
8992
"source": [
@@ -141,7 +144,7 @@
141144
},
142145
{
143146
"cell_type": "code",
144-
"execution_count": null,
147+
"execution_count": 6,
145148
"metadata": {},
146149
"outputs": [],
147150
"source": [
@@ -152,7 +155,7 @@
152155
},
153156
{
154157
"cell_type": "code",
155-
"execution_count": 1,
158+
"execution_count": 7,
156159
"metadata": {},
157160
"outputs": [],
158161
"source": [
@@ -167,7 +170,7 @@
167170
},
168171
{
169172
"cell_type": "code",
170-
"execution_count": null,
173+
"execution_count": 8,
171174
"metadata": {},
172175
"outputs": [],
173176
"source": [
@@ -178,16 +181,24 @@
178181
},
179182
{
180183
"cell_type": "code",
181-
"execution_count": null,
184+
"execution_count": 9,
182185
"metadata": {},
183-
"outputs": [],
186+
"outputs": [
187+
{
188+
"name": "stdout",
189+
"output_type": "stream",
190+
"text": [
191+
"############### Sending Authentication request message to RKD ###############\n"
192+
]
193+
}
194+
],
184195
"source": [
185196
"print('############### Sending Authentication request message to RKD ###############')"
186197
]
187198
},
188199
{
189200
"cell_type": "code",
190-
"execution_count": null,
201+
"execution_count": 10,
191202
"metadata": {},
192203
"outputs": [],
193204
"source": [
@@ -207,7 +218,7 @@
207218
" print('JSON resonse: %s' % (json.dumps(authenResult.json(),sort_keys=True, indent=2, separators=(',', ':'))))\n",
208219
" token = authenResult.json()['CreateServiceToken_Response_1']['Token']\n",
209220
" expire = authenResult.json()['CreateServiceToken_Response_1']['Expiration']\n",
210-
"elif authenResult.status_code is not 200:\n",
221+
"elif authenResult.status_code != 200:\n",
211222
" print('Authenticaion fail with status code %s' % authenResult.status_code)\n",
212223
" if authenResult.status_code == 500:\n",
213224
" print('Error: %s' % (json.dumps(authenResult.json(), sort_keys=True, indent=2, separators=(',', ':'))))"
@@ -271,9 +282,9 @@
271282
"name": "python",
272283
"nbconvert_exporter": "python",
273284
"pygments_lexer": "ipython3",
274-
"version": "3.8.11"
285+
"version": "3.9.7"
275286
}
276287
},
277288
"nbformat": 4,
278-
"nbformat_minor": 2
289+
"nbformat_minor": 4
279290
}

0 commit comments

Comments
 (0)