Skip to content

Commit 5997494

Browse files
author
Wasin Waeosri
committed
revise README.md, modify trkd_authen.py and trkd_quote.py
1 parent a2569c4 commit 5997494

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
# Introduction
2-
This is an example project that shows how to implement TRKD REST Client with python
1+
# TRKD HTTP JSON with Python Example
2+
## Overview
3+
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.
4+
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.Level 2. All data are snapshot (non-streaming) data.
6+
7+
This is an example project that shows how to implement TRKD HTTP JSON Client with python. This project contains the following example scripts for each TRKD services
38
- trkd_authen.py: An example application that shows how to authenticate with TRKD service
49
- trkd_quote.py: An example application that shows how to subscribe (all fields and specific fields) the Quote data from TRKD service
510
- trkd_newsheadline.py: An example application that shows how to subscribe the News Headline data from TRKD service
@@ -11,20 +16,20 @@ This is an example project that shows how to implement TRKD REST Client with pyt
1116
- docs\TRKD_REST_with_Python.docx: A document that describes the trkd_authen.py and trkd_quote.py applications
1217

1318

14-
# prerequisite
19+
## Prerequisite
1520
The following softwares are required to use this script
1621
- Python 2.7.10 or above
1722
- The [requests](http://docs.python-requests.org/en/master/) library
1823

19-
The scripts support Python 2 only
24+
The scripts are based on Python 2 but you can modify it to run with Python 3 (see "Optional - How to run with Python 3" section).
2025

21-
# how to run the script
26+
## How to run the script
2227
Run the script via the command line (or shell)
2328
```
2429
$>python <application>.py
2530
```
2631

27-
# Optional - How to install requests
32+
## Optional - How to install requests
2833
The best way is to get the pip package management tool
2934
1. export <Python_folder>\Scripts to your OS PATH environment
3035
2. call pip command to install requests
@@ -36,7 +41,7 @@ The best way is to get the pip package management tool
3641
export https_proxy="http://<proxy.server>:<port>"
3742
$>pip install requests
3843
```
39-
# Optional - How to run with Python 3
44+
## Optional - How to run with Python 3
4045
You can modify the scripts to run with Python 3 (with requests library installed) by just change the code from "**raw_input()**" to "**input()**" as the following example
4146
- Python 2
4247
```
@@ -47,7 +52,7 @@ You can modify the scripts to run with Python 3 (with requests library installed
4752
username = input('Please input username: ')
4853
```
4954

50-
#Releae Note
55+
## Release Note
5156
- Version 1: 6 Sep 2016
5257
- trkd_authen.py
5358
- trkd_quote.py
@@ -66,4 +71,8 @@ You can modify the scripts to run with Python 3 (with requests library installed
6671
- revise some code
6772
- version 1.0.5: 27 Apr 2017
6873
- revies README.md to support markdown
74+
- version 1.0.6: 3 May 2017
75+
- revies README.md
76+
- modify trkd_authen.py
77+
- modify trkd_quote.py
6978

trkd_quote.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def doSendRequest(url, requestMsg, headers):
2121
##send request
2222
result = requests.post(url, data=json.dumps(requestMsg), headers=headers)
2323
if result.status_code == 500:
24-
print 'Request fail'
25-
print 'response status %s' % result.status_code
26-
print 'Error: %s' % result.json()
24+
print('Request fail')
25+
print('response status %s' % result.status_code)
26+
print('Error: %s' % result.json())
2727
sys.exit(1)
2828
except requests.exceptions.RequestException, e:
29-
print 'Exception!!!'
30-
print e
29+
print('Exception!!!')
30+
print(e)
3131
sys.exit(1)
3232
return result
3333

@@ -39,11 +39,11 @@ def CreateAuthorization(username, password, appid):
3939
authenMsg = {'CreateServiceToken_Request_1': { 'ApplicationID':appid, 'Username':username,'Password':password }}
4040
authenURL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/TokenManagement_1/CreateServiceToken_1'
4141
headers = {'content-type': 'application/json;charset=utf-8'}
42-
print '############### Sending Authentication request message to TRKD ###############'
42+
print('############### Sending Authentication request message to TRKD ###############')
4343
authenResult = doSendRequest(authenURL, authenMsg, headers)
4444
if authenResult is not None and authenResult.status_code == 200:
45-
print 'Authen success'
46-
print 'response status %s'%(authenResult.status_code)
45+
print('Authen success')
46+
print('response status %s'%(authenResult.status_code))
4747
##get Token
4848
token = authenResult.json()['CreateServiceToken_Response_1']['Token']
4949

@@ -77,26 +77,27 @@ def RetrieveQuotes(token, appid):
7777
quoteURL = 'https://api.trkd.thomsonreuters.com/api/Quotes/Quotes.svc/REST/Quotes_1/RetrieveItem_3'
7878
headers = {'content-type': 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token' : token}
7979

80-
print '############### Sending Quote request message to TRKD ###############'
80+
print('############### Sending Quote request message to TRKD ###############')
8181
quoteResult = doSendRequest(quoteURL, quoteRequestMsg,headers)
8282
if quoteResult is not None and quoteResult.status_code == 200:
8383
print 'Quote response message: '
8484
print quoteResult.json()
8585

8686

8787
## ------------------------------------------ Main App ------------------------------------------ ##
88-
##Get username, password and applicationid
89-
username = raw_input('Please input username: ')
90-
##use getpass.getpass to hide user inputted password
91-
password = getpass.getpass(prompt='Please input password: ')
92-
appid = raw_input('Please input appid: ')
93-
94-
95-
token = CreateAuthorization(username,password,appid)
96-
print 'Token = %s'%(token)
97-
## if authentiacation success, continue subscribing Quote
98-
if token is not None:
99-
RetrieveQuotes(token,appid)
88+
89+
if __name__ == '__main__':
90+
## Get username, password and applicationid
91+
username = raw_input('Please input username: ')
92+
## use getpass.getpass to hide user inputted password
93+
password = getpass.getpass(prompt='Please input password: ')
94+
appid = raw_input('Please input appid: ')
95+
96+
token = CreateAuthorization(username,password,appid)
97+
print('Token = %s'%(token))
98+
## if authentiacation success, continue subscribing Quote
99+
if token is not None:
100+
RetrieveQuotes(token,appid)
100101

101102

102103

0 commit comments

Comments
 (0)