Skip to content

Commit 40c29aa

Browse files
author
Wasin Waeosri
committed
Changed logs:
1. Change all thomson reuters word (exception API name) to refinitiv 2. Change time-series scripts to request with trimresponse = false 3. Update json message format
1 parent 4e771cd commit 40c29aa

File tree

10 files changed

+63
-52
lines changed

10 files changed

+63
-52
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Overview
33
The [Thomson Reuters Knowledge Direct (TRKD) API](https://developers.thomsonreuters.com/thomson-reuters-knowledge-direct-trkd) 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.
44

5-
TRKD offers a wide range of Thomson Reuters' information and services delivered in a request-response scenario via web services using today's industry standard protocols (SOAP/XML and REST/JSON). Connectivity can be via HTTP and HTTPS, over the Internet or Delivery Direct. All data are snapshot (non-streaming) data.
5+
TRKD offers a wide range of Refinitiv' information and services delivered in a request-response scenario via web services using today's industry standard protocols (SOAP/XML and REST/JSON). Connectivity can be via HTTP and HTTPS, over the Internet or Delivery Direct. All data are snapshot (non-streaming) data.
66

77
This is an example project that shows how to implement TRKD HTTP JSON client and TRKD Streaming client with Python programming lanugage. This project contains the following example scripts for each TRKD services
88
- trkd_authen.py: An example application that shows how to authenticate with TRKD service
@@ -93,3 +93,5 @@ For further details, please check out the following resources:
9393
- version 1.0.11: January 2019
9494
- Add trkd_wsstreaming.py application for TRKD Streaming service.
9595
- Add License.md file
96+
- version 1.0.12: March 2019
97+
- Change all scripts to print JSON message in beauty format.

trkd_authen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010
import sys

trkd_chart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010

trkd_interday.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010

@@ -66,12 +66,11 @@ def RetrieveInteraday(token, appid):
6666
interdayRequestMsg = {
6767
'GetInterdayTimeSeries_Request_4':{
6868
'Field': fields,
69-
'TrimResponse': True,
69+
'TrimResponse': False,
7070
'Symbol': ricName,
7171
'StartTime':startTime,
7272
'EndTime':endtime,
7373
'Interval':interval,
74-
'TrimResponse': True,
7574
'MetaField': ['NAME','QOS','CCY','TZ','TZOFFSET','NAME_LL']
7675
}
7776
}

trkd_intraday.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010

@@ -76,12 +76,11 @@ def RetrieveIntraday(token, appid):
7676
intradayRequestMsg = {
7777
'GetIntradayTimeSeries_Request_4': {
7878
'Field': fields,
79-
'TrimResponse': True,
79+
'TrimResponse': False,
8080
'Symbol': ricName,
8181
'StartTime': startTime,
8282
'EndTime': endtime,
8383
'Interval': interval,
84-
'TrimResponse': True,
8584
'MetaField': ['NAME', 'QOS', 'CCY', 'TZ', 'TZOFFSET', 'NAME_LL']
8685
}
8786
}

trkd_newsheadline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010
import os

trkd_newsstory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010
import os

trkd_onlinereport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010
import os

trkd_quote.py

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010

@@ -15,96 +15,106 @@
1515
import getpass
1616

1717
# Send HTTP request for all services
18+
19+
1820
def doSendRequest(url, requestMsg, headers):
1921
result = None
2022
try:
21-
##send request
22-
result = requests.post(url, data=json.dumps(requestMsg), headers=headers)
23+
# send request
24+
result = requests.post(
25+
url, data=json.dumps(requestMsg), headers=headers)
2326
# print('outgoing message is %s'%(json.dumps(requestMsg)))
24-
## handle error
27+
# handle error
2528
if result.status_code is not 200:
2629
print('Request fail')
27-
print('response status %s'%(result.status_code))
28-
if result.status_code == 500: ## if username or password or appid is wrong
30+
print('response status %s' % (result.status_code))
31+
if result.status_code == 500: # if username or password or appid is wrong
2932
#print('Error: %s'%(result.json()))
30-
print('Error: %s' % (json.dumps(result.json(),sort_keys=True, indent=2, separators=(',', ':'))))
33+
print('Error: %s' % (json.dumps(result.json(),
34+
sort_keys=True, indent=2, separators=(',', ':'))))
3135
result.raise_for_status()
32-
#if result.status_code == 500:
36+
# if result.status_code == 500:
3337
#print('Request fail')
3438
#print('response status %s' % result.status_code)
3539
#print('Error: %s' % result.json())
36-
#sys.exit(1)
40+
# sys.exit(1)
3741
except requests.exceptions.RequestException as e:
3842
print('Exception!!!')
3943
print(e)
4044
sys.exit(1)
4145
return result
4246

4347

44-
## Perform authentication
48+
# Perform authentication
4549
def CreateAuthorization(username, password, appid):
4650
token = None
47-
##create authentication request URL, message and header
48-
authenMsg = {'CreateServiceToken_Request_1': { 'ApplicationID':appid, 'Username':username,'Password':password }}
51+
# create authentication request URL, message and header
52+
authenMsg = {'CreateServiceToken_Request_1': {
53+
'ApplicationID': appid, 'Username': username, 'Password': password}}
4954
authenURL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/TokenManagement_1/CreateServiceToken_1'
5055
headers = {'content-type': 'application/json;charset=utf-8'}
5156
print('############### Sending Authentication request message to TRKD ###############')
5257
authenResult = doSendRequest(authenURL, authenMsg, headers)
5358
if authenResult and authenResult.status_code == 200:
5459
print('Authen success')
55-
print('response status %s'%(authenResult.status_code))
56-
##get Token
60+
print('response status %s' % (authenResult.status_code))
61+
# get Token
5762
token = authenResult.json()['CreateServiceToken_Response_1']['Token']
58-
63+
5964
return token
6065

61-
## Perform Quote request
66+
# Perform Quote request
67+
68+
6269
def RetrieveQuotes(token, appid):
6370

6471
ricName = input('Please input Symbol: ')
6572
fieldFiltering = input('Subscribe all Field? (Yes|No)')
6673
quoteRequestMsg = None
6774
fieldsName = 'CF_LAST:CF_HIGH:CF_LOW:CF_BID:CF_ASK:CF_YIELD:CF_SOURCE:CF_SRC_PAGE:CF_LOTSIZE:CF_DATE:CF_TIME:CF_TICK:CF_NETCHNG:CF_EXCHNG:CF_VOLUME:CF_CLOSE:CF_OPEN:CF_NAME:CF_CURRENCY'
6875
if fieldFiltering == 'Yes':
69-
## Request all Fields
76+
# Request all Fields
7077
quoteRequestMsg = \
7178
{'RetrieveItem_Request_3': {'TrimResponse': False,
72-
'ItemRequest': [{'RequestKey': [{'Name': ricName, 'NameType': 'RIC'}], 'Scope': 'All',
73-
'ProvideChainLinks': True}]}}
79+
'ItemRequest': [{'RequestKey': [{'Name': ricName, 'NameType': 'RIC'}], 'Scope': 'All',
80+
'ProvideChainLinks': True}]}}
7481
elif fieldFiltering == 'No':
75-
## Request specific Fields
76-
fieldsName = input('Input interested Field Name in the following format (BID:ASK:TRDPRC_1)')
82+
# Request specific Fields
83+
fieldsName = input(
84+
'Input interested Field Name in the following format (BID:ASK:TRDPRC_1)')
7785
quoteRequestMsg = \
7886
{'RetrieveItem_Request_3': {'TrimResponse': False,
79-
'ItemRequest': [{
80-
'RequestKey': [{'Name': ricName, 'NameType': 'RIC'}],
81-
'Fields': fieldsName,
82-
'Scope': 'List',
83-
'ProvideChainLinks': True
84-
}]}}
87+
'ItemRequest': [{
88+
'RequestKey': [{'Name': ricName, 'NameType': 'RIC'}],
89+
'Fields': fieldsName,
90+
'Scope': 'List',
91+
'ProvideChainLinks': True
92+
}]}}
8593

8694
quoteURL = 'https://api.trkd.thomsonreuters.com/api/Quotes/Quotes.svc/REST/Quotes_1/RetrieveItem_3'
87-
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
88-
95+
headers = {'content-type': 'application/json;charset=utf-8',
96+
'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token': token}
97+
8998
print('############### Sending Quote request message to TRKD ###############')
90-
quoteResult = doSendRequest(quoteURL, quoteRequestMsg,headers)
99+
quoteResult = doSendRequest(quoteURL, quoteRequestMsg, headers)
91100
if quoteResult and quoteResult.status_code == 200:
92101
print('Quote response message: ')
93-
#print(quoteResult.json())
94-
print(json.dumps(quoteResult.json(), sort_keys=True,indent=2, separators=(',', ':')))
102+
# print(quoteResult.json())
103+
print(json.dumps(quoteResult.json(), sort_keys=True,
104+
indent=2, separators=(',', ':')))
95105

96106

97107
## ------------------------------------------ Main App ------------------------------------------ ##
98108

99109
if __name__ == '__main__':
100-
## Get username, password and applicationid
110+
# Get username, password and applicationid
101111
username = input('Please input username: ')
102-
## use getpass.getpass to hide user inputted password
112+
# use getpass.getpass to hide user inputted password
103113
password = getpass.getpass(prompt='Please input password: ')
104114
appid = input('Please input appid: ')
105115

106-
token = CreateAuthorization(username,password,appid)
107-
print('Token = %s'%(token))
108-
## if authentiacation success, continue subscribing Quote
116+
token = CreateAuthorization(username, password, appid)
117+
print('Token = %s' % (token))
118+
# if authentiacation success, continue subscribing Quote
109119
if token:
110-
RetrieveQuotes(token,appid)
120+
RetrieveQuotes(token, appid)

trkd_wsstreaming.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We offer this code to provide developers practical and useful guidance while developing their own code.
55
However, we do not offer support and troubleshooting of issues that are related to the use of this code
66
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at http://customers.thomsonreuters.com
7+
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
88
for additional information regarding the TRKD API.'''
99

1010
import os
@@ -58,7 +58,8 @@ def doSendRequest(url, requestMsg, headers):
5858
print('Request fail')
5959
print('response status %s'%(result.status_code))
6060
if result.status_code == 500: ## if username or password or appid is wrong
61-
print('Error: %s'%(result.json()))
61+
#print('Error: %s'%(result.json()))
62+
print('Error: %s' % (json.dumps(result.json(),sort_keys=True, indent=2, separators=(',', ':'))))
6263
result.raise_for_status()
6364
except requests.exceptions.RequestException as e:
6465
print('Exception!!!')

0 commit comments

Comments
 (0)