Last update | Jan 2021 |
Operating System | Any |
Interpreter | Python 3.x |
Refinitiv Data Platform (RDP) provides streaming and non-streaming data through Elektron Websocket interface and REST API respectively. In both the cases, an application begins by invoking a REST API call to get an authorization token. For request-response API, all subsequent calls will use this token to get the data. The token protocol uses OAuth 2.0 specification and can be implemented in any programming language. In this quick-start, we will run a Python application, which will request an access token and then use it to get time-series data. The acquired token can be used to access other data services as well.
Note that the LSEG authentication service has limits set for usage in order to protect clients from service loss due to a denial of service (DOS) attack. Performance testing of client applications may trigger this security control if authentication rates are significant (more than 50 login requests or session token refreshes per minute). As such, LSEG strongly recommends that you ensure that authentication requests to LSEG remain at relatively low request rates in order to avoid triggering security controls.
1. Setup Python environment
If Python is not already installed on your machine, download and install Python 3.x from Python Website. Python 3.x is preferred over older versions. This sample uses Requests library for doing raw HTTP interactions to avoid installing any additional packages. Since Python libraries can have version dependencies, it is advisable to separate those using containers. See the Python environment setup tutorial.
2. Download the sample source code
Download the Quickstart and Tutorial source code archive file. It is a simple Python program to:
3. Run it
To try out the sample, you will need the following information. Please see your Refinitiv Data Platform welcome email, or contact your account manager to get the appropriate username/password for RDP. Since this sample makes a time-series data call, it is important that the user has the authorization to get historical pricing data.
Variable | Definition |
---|---|
USERNAME | The ID of the user. You typically receive 2 IDs within your welcome email, your email and a Machine ID.
|
PASSWORD | The password that corresponds to the USERNAME being used:
|
CLIENT_ID | The client_id is an OAuth term but is used to represent an AppKey. This is a unique ID defined for an application making the request. Users can generate/manage their AppKey's here. Make sure:
Otherwise, the Register New App button will remain disabled. |
Edit the credentials.ini file and specify your username, password and your client ID.
NOTE: Whilst the rdpToken.py file also has a user credentials section at the start of the file, if a credentials.ini exists in the same folder, it will override any credentials in rpdToken.py.
The REST API endpoint is hardcoded in the file and does not have to change. To run the sample, open a command prompt where the sample is downloaded, and type in the following command:
NOTE: Since this sample makes a time-series data call, it is important that the user has the authorization to get historical pricing data. You can contact your account manager to get the appropriate username/password for your account that has an access to the protected RDP resource of your interest.
python timeSeries.py
The output should look something like this:
4. Understanding the output
Sample begins by reading the token from a local file. If the token is expired or if the file does not exist, a new one is requested. Next this token is used to invoke the time-series API call. In this simple example, a Python for-loop extracts and displays the JSON response object. Users familiar with Pandas library can use that to easily slice and format the data.
The run output from your test should match the sample shown in the screen-shot. If there are errors in the output, or if it does not match the expected output, recheck the configured variables in the Python source code.
The key reasons for failure will be:
{"error":"access_denied" ,"error_description":"Invalid username or password."} - Invalid username or password. Recheck that username and password have been correctly typed in.
{"error":"access_denied" ,"error_description":"Found temporary password. It must be changed. Input newPassword field to change password."} - The user is logging in for first time and needs to change their password. Please run the password change sample included in the download package. You can read about password change fields in the tutorial.
You can ask API related questions in the developers forum.
Please visit the step by step tutorials to understand these functions and how this sample is built.
The sample code in python: QuickStart and Tutorial source code.