Skip to content

Commit 10669ad

Browse files
committed
add python console code
1 parent 1a593d8 commit 10669ad

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Python/.ipynb_checkpoints
22
Python/.env
3+
Python/esg_data.json
34

45
Java/
56
Java/.idea

Python/rdp_apis_console.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
import json
3+
from dotenv import load_dotenv
4+
import requests
5+
6+
if __name__ == '__main__':
7+
8+
client_secret = ''
9+
scope = 'trapi'
10+
universe = '7203.T'
11+
12+
load_dotenv()
13+
14+
print(os.getenv('RTO_USER'))
15+
16+
# RDP Login
17+
auth_endpoint = os.getenv('RDP_WS_AUTH_URL')
18+
# -- Init and Authenticate Session
19+
auth_request_msg = {
20+
'username': os.getenv('RDP_USER') ,
21+
'password': os.getenv('RDP_PASSWORD') ,
22+
'grant_type': "password",
23+
'scope': scope,
24+
'takeExclusiveSignOnControl': "true"
25+
}
26+
27+
try:
28+
response = requests.post(auth_endpoint, headers = {'Accept':'application/json'}, data = auth_request_msg, auth = (os.getenv('RDP_APP_KEY'), client_secret))
29+
except Exception as exp:
30+
print('Caught exception: %s' % str(exp))
31+
32+
if response.status_code == 200: # HTTP Status 'OK'
33+
print('Authentication success')
34+
auth_obj = response.json()
35+
else:
36+
print('RDP authentication result failure: %s %s' % (response.status_code, response.reason))
37+
print('Text: %s' % (response.text))
38+
39+
# ESG Data
40+
esg_url = os.getenv('RDP_ESG_URP')
41+
payload = {'universe': universe}
42+
43+
try:
44+
response = requests.get(esg_url, headers={'Authorization': 'Bearer {}'.format(auth_obj['access_token'])}, params = payload)
45+
except Exception as exp:
46+
print('Caught exception: %s' % str(exp))
47+
48+
if response.status_code == 200: # HTTP Status 'OK'
49+
print('This is a ESG data result from RDP API Call')
50+
print(response.json())
51+
esg_object=response.json()
52+
else:
53+
print('RDP APIs: ESG data request failure: %s %s' % (response.status_code, response.reason))
54+
print('Text: %s' % (response.text))
55+
56+
print('\n')
57+
58+
59+
60+
# https://developers.refinitiv.com/en/article-catalog/article/using-rdp-api-request-esg-data-jupyter-notebook
61+
import pandas as pd
62+
import numpy as np
63+
headers=esg_object['headers']
64+
65+
#Get column headers/titles using lambda
66+
titles=map(lambda header:header['title'], headers)
67+
68+
dataArray=np.array(esg_object['data'])
69+
df=pd.DataFrame(data=dataArray,columns=titles)
70+
71+
if df.empty is False:
72+
print(df)

Python/requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
certifi==2021.5.30
2+
charset-normalizer==2.0.3
3+
cycler==0.10.0
4+
idna==3.2
5+
kiwisolver==1.3.1
6+
matplotlib==3.4.2
7+
numpy==1.21.1
8+
pandas==1.3.1
9+
Pillow==8.3.1
10+
pyparsing==2.4.7
11+
python-dateutil==2.8.2
12+
python-dotenv==0.19.0
13+
pytz==2021.1
14+
requests==2.26.0
15+
six==1.16.0
16+
urllib3==1.26.6
17+
wincertstore==0.2

0 commit comments

Comments
 (0)