Skip to content

Commit 396ebe0

Browse files
committed
change logs:
1. Update trkd_interday.py and trk_intraday.py to be V5 operations 2. Update README.md
1 parent adc61e9 commit 396ebe0

File tree

3 files changed

+62
-49
lines changed

3 files changed

+62
-49
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ Please follow the [classic Jupyter Notebook installation guide](https://jupyter.
6868

6969
## References
7070
For further details, please check out the following resources:
71-
* [Thomson Reuters Knowledge Direct API page](https://developers.thomsonreuters.com/thomson-reuters-knowledge-direct-trkd) on the [Thomson Reuters Developer Community](https://developers.thomsonreuters.com/) web site.
71+
* [Thomson Reuters Knowledge Direct API page](https://developers.refinitiv.com/thomson-reuters-knowledge-direct-trkd) on the [Thomson Reuters Developer Community](https://developers.refinitiv.com/) web site.
7272
* [Thomson Reuters Knowledge Direct API Catalog](https://www.trkd.thomsonreuters.com/SupportSite/RequestBuilder/requestbuilder.aspx) web site.
73-
* [Elektron WebSocket API](https://developers.thomsonreuters.com/websocket-api) page on the [Thomson Reuters Developer Community](https://developers.thomsonreuters.com/) web site.
73+
* [Elektron WebSocket API](https://developers.refinitiv.com/websocket-api) page on the [Thomson Reuters Developer Community](https://developers.refinitiv.com/) web site.
7474

7575
## Release Note
7676
- Version 1: 6 Sep 2016
@@ -116,3 +116,5 @@ For further details, please check out the following resources:
116116
- Add TRKD Authentication Jupyter Notebook.
117117
- version 1.5.1: July 2019
118118
- Add TRKD Interday and Intraday Jupyter Notebooks.
119+
- version 1.5.2: October 2019
120+
- Update TRKD Interday and Intraday services operations.

trkd_interday.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
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()
3236
except requests.exceptions.RequestException as e:
3337
print('Exception!!!')
@@ -36,68 +40,75 @@ def doSendRequest(url, requestMsg, headers):
3640
return result
3741

3842

39-
## Perform authentication
43+
# Perform authentication
4044
def CreateAuthorization(username, password, appid):
4145
token = None
42-
##create authentication request URL, message and header
43-
authenMsg = {'CreateServiceToken_Request_1': { 'ApplicationID':appid, 'Username':username,'Password':password }}
46+
# create authentication request URL, message and header
47+
authenMsg = {'CreateServiceToken_Request_1': {
48+
'ApplicationID': appid, 'Username': username, 'Password': password}}
4449
authenURL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/TokenManagement_1/CreateServiceToken_1'
4550
headers = {'content-type': 'application/json;charset=utf-8'}
4651
print('############### Sending Authentication request message to TRKD ###############')
4752
authenResult = doSendRequest(authenURL, authenMsg, headers)
4853
if authenResult and authenResult.status_code == 200:
4954
print('Authen success')
50-
print('response status %s'%(authenResult.status_code))
51-
##get Token
55+
print('response status %s' % (authenResult.status_code))
56+
# get Token
5257
token = authenResult.json()['CreateServiceToken_Response_1']['Token']
53-
58+
5459
return token
5560

56-
## Perform Interday request
61+
# Perform Interday request
62+
63+
5764
def RetrieveInteraday(token, appid):
58-
##construct Time Series Interday request message
65+
# construct Time Series Interday request message
5966
ricName = input('Please input Symbol: ')
6067
interdayRequestMsg = None
61-
fields = ['OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK'] #change your fields (support these 'OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK' fields only)
62-
startTime = '2015-09-22T00:00:00' #change your StartTime
63-
endtime = '2016-09-22T23:59:00' #change your EndTime
64-
#interval = 'DAILY' # change your interval between 'DAILY', 'WEEKLY', 'MONTHLY', 'QUARTERLY' and 'ANNUAL'
65-
interval = input('Input interested interval (\'DAILY\' or \'WEEKLY\' or \'MONTHLY\' or \'QUARTERLY\' or \'ANNUAL\'): ')
68+
# change your fields (support these 'OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK' fields only)
69+
fields = ['OPEN', 'HIGH', 'LOW', 'CLOSE',
70+
'CLOSEYIELD', 'VOLUME', 'BID', 'ASK']
71+
startTime = '2015-09-22T00:00:00' # change your StartTime
72+
endtime = '2016-09-22T23:59:00' # change your EndTime
73+
# interval = 'DAILY' # change your interval between 'DAILY', 'WEEKLY', 'MONTHLY', 'QUARTERLY' and 'ANNUAL'
74+
interval = input(
75+
'Input interested interval (\'DAILY\' or \'WEEKLY\' or \'MONTHLY\' or \'QUARTERLY\' or \'ANNUAL\'): ')
6676
interdayRequestMsg = {
67-
'GetInterdayTimeSeries_Request_4':{
77+
'GetInterdayTimeSeries_Request_5': {
6878
'Field': fields,
6979
'TrimResponse': False,
7080
'Symbol': ricName,
71-
'StartTime':startTime,
72-
'EndTime':endtime,
73-
'Interval':interval,
74-
'MetaField': ['NAME','QOS','CCY','TZ','TZOFFSET','NAME_LL']
81+
'StartTime': startTime,
82+
'EndTime': endtime,
83+
'Interval': interval,
84+
'MetaField': ['NAME', 'QOS', 'CCY', 'TZ', 'TZOFFSET', 'NAME_LL']
7585
}
7686
}
77-
##construct Time Series Interday URL and header
78-
#interdayURL = 'http://api.rkd.reuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_4'
79-
interdayURL = 'http://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_4'
80-
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
81-
87+
# construct Time Series Interday URL and header
88+
#interdayURL = 'http://api.rkd.reuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_5'
89+
interdayURL = 'http://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_5'
90+
headers = {'content-type': 'application/json;charset=utf-8',
91+
'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token': token}
92+
8293
print('############### Sending Time Series Interday request message to TRKD ###############')
8394
interdayResult = doSendRequest(interdayURL, interdayRequestMsg, headers)
8495
if interdayResult and interdayResult.status_code == 200:
8596
print('Time Series Interday response message: ')
86-
#print(interdayResult.json())
87-
print(json.dumps(interdayResult.json(), sort_keys=True, indent=2, separators=(',', ':')))
88-
97+
# print(interdayResult.json())
98+
print(json.dumps(interdayResult.json(),
99+
sort_keys=True, indent=2, separators=(',', ':')))
89100

90101

91102
## ------------------------------------------ Main App ------------------------------------------ ##
92103
if __name__ == '__main__':
93-
##Get username, password and applicationid
104+
# Get username, password and applicationid
94105
username = input('Please input username: ')
95-
##use getpass.getpass to hide user inputted password
106+
# use getpass.getpass to hide user inputted password
96107
password = getpass.getpass(prompt='Please input password: ')
97108
appid = input('Please input appid: ')
98109

99110
token = CreateAuthorization(username, password, appid)
100-
print('Token = %s'%(token))
101-
## if authentiacation success, continue subscribing Time Series interday
111+
print('Token = %s' % (token))
112+
# if authentiacation success, continue subscribing Time Series interday
102113
if token:
103114
RetrieveInteraday(token, appid)

trkd_intraday.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'''
2-
The TRKD API sample code is provided for informational purposes only
3-
and without knowledge or assumptions of the end users development environment.
4-
We offer this code to provide developers practical and useful guidance while developing their own code.
5-
However, we do not offer support and troubleshooting of issues that are related to the use of this code
6-
in a particular environment; it is offered solely as sample code for guidance.
7-
Please see the Thomson Reuters Knowledge Direct product page at https://my.refinitiv.com
2+
The TRKD API sample code is provided for informational purposes only
3+
and without knowledge or assumptions of the end users development environment.
4+
We offer this code to provide developers practical and useful guidance while developing their own code.
5+
However, we do not offer support and troubleshooting of issues that are related to the use of this code
6+
in a particular environment; it is offered solely as sample code for guidance.
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

@@ -29,7 +29,7 @@ def doSendRequest(url, requestMsg, headers):
2929
print('Request fail')
3030
print('response status %s' % (result.status_code))
3131
if result.status_code == 500: # if username or password or appid is wrong
32-
#print('Error: %s' % (result.json()))
32+
# print('Error: %s' % (result.json()))
3333
print('Error: %s' % (json.dumps(result.json(),
3434
sort_keys=True, indent=2, separators=(',', ':'))))
3535
result.raise_for_status()
@@ -68,13 +68,13 @@ def RetrieveIntraday(token, appid):
6868
# change your fields (support these 'OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK' fields only)
6969
fields = ['OPEN', 'HIGH', 'LOW', 'CLOSE',
7070
'CLOSEYIELD', 'VOLUME', 'BID', 'ASK']
71-
startTime = '2016-09-12T00:00:00' # change your StartTime
72-
endtime = '2016-09-19T23:59:00' # change your EndTime
71+
startTime = '2019-09-12T00:00:00' # change your StartTime
72+
endtime = '2019-09-19T23:59:00' # change your EndTime
7373
# interval = 'MINUTE' # change your interval between 'MINUTE', '5MINUTES', '30MINUTES' and 'HOUR'
7474
interval = input(
7575
'Input interested interval (\'MINUTE\' or \'5MINUTES\' or \'30MINUTES\' or \'HOUR\'): ')
7676
intradayRequestMsg = {
77-
'GetIntradayTimeSeries_Request_4': {
77+
'GetIntradayTimeSeries_Request_5': {
7878
'Field': fields,
7979
'TrimResponse': False,
8080
'Symbol': ricName,
@@ -85,7 +85,7 @@ def RetrieveIntraday(token, appid):
8585
}
8686
}
8787
# construct Time Series Intraday URL and header
88-
intradayURL = 'http://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetIntradayTimeSeries_4'
88+
intradayURL = 'http://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetIntradayTimeSeries_5'
8989
headers = {'content-type': 'application/json;charset=utf-8',
9090
'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token': token}
9191

0 commit comments

Comments
 (0)