Skip to content

Commit 3e40bf3

Browse files
author
Wasin Waeosri
committed
reviese all comments
1 parent 1916112 commit 3e40bf3

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

trkd_chart.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ def CreateAuthorization(username, password, appid):
5050

5151
return token
5252

53-
## Perform Quote request
53+
## Perform Chart request
5454
def RetrieveChart(token, appid):
55-
55+
##construct a Chart request message
5656
ricName = raw_input('Please input Symbol: ')
57+
5758
chartRequestMsg = {'GetChart_Request_2': {'chartRequest': {
5859
'TimeSeries': {'TimeSeriesRequest_typehint': ['TimeSeriesRequest'],
5960
'TimeSeriesRequest': [{'Symbol': ricName,
@@ -270,15 +271,16 @@ def RetrieveChart(token, appid):
270271
'Culture': 'en-US',
271272
'ReturnPrivateNetworkURL': False,
272273
}}}
273-
274-
interdayURL = 'http://api.rkd.reuters.com/api/Charts/Charts.svc/REST/Charts_1/GetChart_2'
274+
##construct Chart URL and header
275+
chartURL = 'http://api.rkd.reuters.com/api/Charts/Charts.svc/REST/Charts_1/GetChart_2'
275276
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
276277

277278
print '############### Sending Chart request message to TRKD ###############'
278-
chartResult = doSendRequest(interdayURL, chartRequestMsg,headers)
279+
chartResult = doSendRequest(chartURL, chartRequestMsg,headers)
279280
if chartResult is not None and chartResult.status_code == 200:
280281
print 'Time Series Interday response message: '
281282
print chartResult.json()
283+
##print returned server, tag and image url
282284
server = chartResult.json()['GetChart_Response_2']['ChartImageResult']['Server']
283285
print '\nServer: %s'%(server)
284286
tag = chartResult.json()['GetChart_Response_2']['ChartImageResult']['Tag']
@@ -287,12 +289,16 @@ def RetrieveChart(token, appid):
287289
print 'Url: %s'%(imageUrl)
288290
return imageUrl
289291

292+
##download image url from the TRKD Chart service as chart.png
290293
def downloadChartImage(chartURL):
294+
##create header
291295
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
292296
headers = { 'User-Agent' : user_agent }
293297
print '\nDownlading chart.png file from %s'%(chartURL)
298+
##download image using Python urllib2
294299
downloadResult = urllib2.Request(chartURL, headers=headers)
295300
imgData = urllib2.urlopen(downloadResult).read()
301+
##write file
296302
fileName = './chart.png'
297303
with open(fileName,'wb') as outfile:
298304
outfile.write(imgData)
@@ -309,9 +315,10 @@ def downloadChartImage(chartURL):
309315

310316
token = CreateAuthorization(username,password,appid)
311317
print 'Token = %s'%(token)
312-
## if authentiacation success, continue subscribing Time Series intraday
318+
## if authentiacation success, continue subscribing Chart
313319
if token is not None:
314320
chartURL = RetrieveChart(token,appid)
321+
## if chart request success, continue downloading Chart image
315322
if chartURL is not None:
316323
print '############### Downloading Chart file from TRKD ###############'
317324
downloadChartImage(chartURL)

trkd_interday.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def CreateAuthorization(username, password, appid):
4949

5050
return token
5151

52-
## Perform Quote request
52+
## Perform Interday request
5353
def RetrieveInteraday(token, appid):
54-
54+
##construct Time Series Interday request message
5555
ricName = raw_input('Please input Symbol: ')
5656
interdayRequestMsg = None
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)
@@ -71,7 +71,7 @@ def RetrieveInteraday(token, appid):
7171
'MetaField': ['NAME','QOS','CCY','TZ','TZOFFSET','NAME_LL']
7272
}
7373
}
74-
74+
##construct Time Series Interday URL and header
7575
interdayURL = 'http://api.rkd.reuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_4'
7676
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
7777

@@ -91,7 +91,7 @@ def RetrieveInteraday(token, appid):
9191

9292
token = CreateAuthorization(username,password,appid)
9393
print 'Token = %s'%(token)
94-
## if authentiacation success, continue subscribing Time Series intraday
94+
## if authentiacation success, continue subscribing Time Series interday
9595
if token is not None:
9696
RetrieveInteraday(token,appid)
9797

trkd_intraday.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def CreateAuthorization(username, password, appid):
4949

5050
return token
5151

52-
## Perform Quote request
52+
## Perform Intraday request
5353
def RetrieveIntraday(token, appid):
54-
54+
##construct Time Series Intraday request message
5555
ricName = raw_input('Please input Symbol: ')
5656
intradayRequestMsg = None
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)
@@ -71,7 +71,7 @@ def RetrieveIntraday(token, appid):
7171
'MetaField': ['NAME','QOS','CCY','TZ','TZOFFSET','NAME_LL']
7272
}
7373
}
74-
74+
##construct Time Series Intraday URL and header
7575
intradayURL = 'http://api.rkd.reuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetIntradayTimeSeries_4'
7676
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
7777

trkd_newsheadline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def RetrieveNewsHeadline(token, appid):
8989
token = CreateAuthorization(username,password,appid)
9090
print 'Token = %s'%(token)
9191

92-
## if authentiacation success, continue subscribing Quote
92+
## if authentiacation success, continue subscribing News Headline
9393
if token is not None:
9494
RetrieveNewsHeadline(token,appid)
9595

trkd_newsstory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def CreateAuthorization(username, password, appid):
4949

5050
## Perform News Story request
5151
def RetrieveNewsStory(token, appid):
52-
##construct news headline URL and header
52+
##construct news story URL and header
5353
newsURL = 'http://api.rkd.reuters.com/api/News/News.svc/REST/News_1/RetrieveStoryML_1'
5454
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
55-
##construct a news headline story message
55+
##construct a news story request message
5656
storyid = raw_input('Please input news story id: ')
5757
newsRequestMsg = {'RetrieveStoryML_Request_1': {
5858
'StoryMLRequest':{
@@ -78,7 +78,7 @@ def RetrieveNewsStory(token, appid):
7878
token = CreateAuthorization(username,password,appid)
7979
print 'Token = %s'%(token)
8080

81-
## if authentiacation success, continue subscribing Quote
81+
## if authentiacation success, continue subscribing News Story
8282
if token is not None:
8383
RetrieveNewsStory(token,appid)
8484

trkd_onlinereport.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def CreateAuthorization(username, password, appid):
4747

4848
return token
4949

50-
## Perform News Headline request
50+
## Perform Online Report request
5151
def RetrieveOnlineReport(token, appid):
52-
##construct news headline URL and header
52+
##construct Online Report URL and header
5353
onlinereportURL = 'http://api.rkd.reuters.com/api/OnlineReports/OnlineReports.svc/REST/OnlineReports_1/GetSummaryByTopic_1'
5454
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
55-
##construct a news headline request message
55+
##construct a Online Report request message
5656
onelinereportRequestMsg = {'GetSummaryByTopic_Request_1': {
5757
'Topic': 'OLRUTOPNEWS',
5858
'MaxCount': 20,
@@ -62,7 +62,7 @@ def RetrieveOnlineReport(token, appid):
6262
print '############### Sending News - Online Report request message to TRKD ###############'
6363
onlinereportResult = doSendRequest(onlinereportURL, onelinereportRequestMsg,headers)
6464
if onlinereportResult is not None and onlinereportResult.status_code == 200:
65-
print 'News Headline response message: '
65+
print 'Online Report response message: '
6666
print onlinereportResult.json()
6767

6868

@@ -77,7 +77,7 @@ def RetrieveOnlineReport(token, appid):
7777
token = CreateAuthorization(username,password,appid)
7878
print 'Token = %s'%(token)
7979

80-
## if authentiacation success, continue subscribing Quote
80+
## if authentiacation success, continue subscribing Online Report
8181
if token is not None:
8282
RetrieveOnlineReport(token,appid)
8383

0 commit comments

Comments
 (0)