Skip to content

Commit 99a413b

Browse files
author
Wasin Waeosri
committed
done interday and change TS interval input logic
1 parent 51de3ab commit 99a413b

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed

trkd_interday.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'''
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 http://customers.thomsonreuters.com
8+
for additional information regarding the TRKD API.'''
9+
10+
11+
import os
12+
import sys
13+
import requests
14+
import json
15+
import getpass
16+
17+
18+
def doSendRequest(url, requestMsg, headers):
19+
result = None
20+
try:
21+
##send request
22+
result = requests.post(url, data=json.dumps(requestMsg), headers=headers)
23+
if result.status_code == 500:
24+
print 'Request fail'
25+
print 'response status %s' % result.status_code
26+
print 'Error: %s' % result.json()
27+
sys.exit(1)
28+
except requests.exceptions.RequestException, e:
29+
print 'Exception!!!'
30+
print e
31+
sys.exit(1)
32+
return result
33+
34+
35+
## Perform authentication
36+
def CreateAuthorization(username, password, appid):
37+
token = None
38+
##create authentication request URL, message and header
39+
authenMsg = {'CreateServiceToken_Request_1': { 'ApplicationID':appid, 'Username':username,'Password':password }}
40+
authenURL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/TokenManagement_1/CreateServiceToken_1'
41+
headers = {'content-type': 'application/json;charset=utf-8'}
42+
print '############### Sending Authentication request message to TRKD ###############'
43+
authenResult = doSendRequest(authenURL, authenMsg, headers)
44+
if authenResult is not None and authenResult.status_code == 200:
45+
print 'Authen success'
46+
print 'response status %s'%(authenResult.status_code)
47+
##get Token
48+
token = authenResult.json()['CreateServiceToken_Response_1']['Token']
49+
50+
return token
51+
52+
## Perform Quote request
53+
def RetrieveInteraday(token, appid):
54+
55+
ricName = raw_input('Please input Symbol: ')
56+
interdayRequestMsg = None
57+
fields = ['OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK'] #change your fields (support these 'OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK' fields only)
58+
startTime = '2015-09-22T00:00:00' #change your StartTime
59+
endtime = '2016-09-22T23:59:00' #change your EndTime
60+
#interval = 'DAILY' # change your interval between 'DAILY', 'WEEKLY', 'MONTHLY', 'QUARTERLY' and 'ANNUAL'
61+
interval = raw_input('Input interested interval (\'DAILY\' or \'WEEKLY\' or \'MONTHLY\' or \'QUARTERLY\' or \'ANNUAL\'): ')
62+
interdayRequestMsg = {
63+
'GetInterdayTimeSeries_Request_4':{
64+
'Field': fields,
65+
'TrimResponse': True,
66+
'Symbol': ricName,
67+
'StartTime':startTime,
68+
'EndTime':endtime,
69+
'Interval':interval,
70+
'TrimResponse': True,
71+
'MetaField': ['NAME','QOS','CCY','TZ','TZOFFSET','NAME_LL']
72+
}
73+
}
74+
75+
interdayURL = 'http://api.rkd.reuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_4'
76+
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
77+
78+
print '############### Sending Time Series Interday request message to TRKD ###############'
79+
interdayResult = doSendRequest(interdayURL, interdayRequestMsg,headers)
80+
if interdayResult is not None and interdayResult.status_code == 200:
81+
print 'Time Series Interday response message: '
82+
print interdayResult.json()
83+
84+
85+
## ------------------------------------------ Main App ------------------------------------------ ##
86+
##Get username, password and applicationid
87+
username = raw_input('Please input username: ')
88+
##use getpass.getpass to hide user inputted password
89+
password = getpass.getpass(prompt='Please input password: ')
90+
appid = raw_input('Please input appid: ')
91+
92+
token = CreateAuthorization(username,password,appid)
93+
print 'Token = %s'%(token)
94+
## if authentiacation success, continue subscribing Time Series intraday
95+
if token is not None:
96+
RetrieveInteraday(token,appid)
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+

trkd_intraday.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ def RetrieveIntraday(token, appid):
5757
fields = ['OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK'] #change your fields (support these 'OPEN','HIGH','LOW','CLOSE','CLOSEYIELD','VOLUME','BID','ASK' fields only)
5858
startTime = '2016-09-12T00:00:00' #change your StartTime
5959
endtime = '2016-09-19T23:59:00' #change your EndTime
60+
#interval = 'MINUTE' # change your interval between 'MINUTE', '5MINUTES', '30MINUTES' and 'HOUR'
61+
interval = raw_input('Input interested interval (\'MINUTE\' or \'5MINUTES\' or \'30MINUTES\' or \'HOUR\'): ')
6062
intradayRequestMsg = {
6163
'GetIntradayTimeSeries_Request_4':{
6264
'Field': fields,
6365
'TrimResponse': True,
6466
'Symbol': ricName,
6567
'StartTime':startTime,
6668
'EndTime':endtime,
67-
'Interval':'MINUTE',
69+
'Interval':interval,
6870
'TrimResponse': True,
6971
'MetaField': ['NAME','QOS','CCY','TZ','TZOFFSET','NAME_LL']
7072
}

0 commit comments

Comments
 (0)