Accessing TRTH Intraday summaries in python

Hi, I am trying to use python to retrieve intraday summary data. The first step is fine and I get the token without issue. I then make my request and get the 202 response as expected.
When I then poll the response, it initially says it's not yet complete, and will try again. However after that it states an error has occurred and the job seems to time out.
I have attached screenshots, can you clarify if I'm doing something wrong? Note this exact same process has worked previously about a month ago so not sure if the product has been updated since. Thanks
Best Answer
-
Hi @jack.coppinger1,
Thanks for the code. I have tried it but cannot replicate the issue. Could you modify the code to use token variable instead of copied value for the requestHeaders? This is to ensure that the token value is valid when the requests are sent. Also, once you try the code, please run the token request step first to get new valid token.
Below is the sample.
#Step 2: send an on demand extraction request using the received token
requestUrl='https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/ExtractRaw';
requestHeaders={
"Prefer":"respond-async",
"Content-Type":"application/json",
"Authorization": "token " + token
}#If status is 202, display the location url we received, and will use to poll the status of the extraction request:
if status_code == 202 :
requestUrl = r2.headers["location"]
print ('Extraction is not complete, we shall poll the location URL:')
print (str(requestUrl))
requestHeaders={
"Prefer":"respond-async",
"Content-Type":"application/json",
"Authorization":"token " + token
}0
Answers
-
From the code, the token is hard code.
Are you using an expired token? The token remains valid for 24 hours.
I got the same 401 error if I used an expired token. You can print the body in the response message to verify the problem. In my case, I got:
{
"error": {
"message": "Authentication request failed because of invalid token"
}
}Please make sure that you are using the current token retrieved when calling https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken.
Otherwise, you can use the POST method with
https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/ValidateToken(Token='<token>') to verify the token.
0 -
Hi, thank you for response. I don't believe this is the issue. I generate the token in the first response:
I then paste this same token into the initial request:
Also when I run the extraction I get a 202 response, which indicates it's been accepted by the server and is in progress?
It's the next step when polling to see if the job is complete that the issue seems to be. It polls once, then again after 30 seconds, if the job isn't done it gives me an error rather than repeating
0 -
Hi @jack.coppinger1,
The issue might be in the "Authorization" header created for the polling request. Can you add "+" as follows. If there still be an issue, please provide your code in text format so I can try to replicate the issue.
"Authorization":"token " + "<your token>"
0 -
hi @veerapath.rungruengrayubkul, when I added the + I got a timeout error
My request to get the token is:
filePath = "/Users/u6069419/Downloads/" #Location to save downloaded files
fileNameRoot = "Python_Test" #Root of the name for the downloaded files
myUsername = "myUsername"
myPassword = "myPassword"
useAws = True
#Set the last parameter above to:
# False to download from TRTH servers
# True to download from Amazon Web Services cloud (recommended, it is faster)
#Imports:
import requests
import json
import shutil
import time
import urllib3
import gzip
#====================================================================================
#Step 1: token request
requestUrl = "https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken"
requestHeaders={
"Prefer":"respond-async",
"Content-Type":"application/json"
}
requestBody={
"Credentials": {
"Username": 9021083,
"Password": "xxxxxxx"
}
}
r1 = requests.post(requestUrl, json=requestBody,headers=requestHeaders)
if r1.status_code == 200 :
jsonResponse = json.loads(r1.text.encode('ascii', 'ignore'))
token = jsonResponse["value"]
print ('Authentication token (valid 24 hours):')
print (token)
else:
print ('Replace myUserName and myPassword with valid credentials, then repeat the request')
Then the next request is:
requestHeaders={
"Prefer":"respond-async",
"Content-Type":"application/json",
"Authorization": "token " "_XDMENamXOk0ULRojIsNRXQpvDKZgntjVzjxP1PsdBKP1CC136gxdntVx7JnfHAHSeCcwYnFLxxU6vEo1CHZMaQL7qZVDa7qJgJ90VcI_lwpMzx7AbME5DFIC2X8hK0lpZWJZkFpI9SzYujTHtuT3b7b2S7gLt2BSCIjCktJpWmCTV7v6F962WgPpn2UYym6Wf_w5VfhzYyWXKYazSrzhPdoYZWTHufIFr4bK-bcw8TN4jY1VJiRXdNatvairq9q_jLVZcIcjLLJymiIMgeaZTUXn5JQqw0UtlkOixiLI2Gc"
}
requestBody={
"ExtractionRequest": {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.TickHistoryIntradaySummariesExtractionRequest",
"ContentFieldNames": [
"Close Ask",
"Close Bid",
"High",
"High Ask",
"High Bid",
"Last",
"Low",
"Low Ask",
"Low Bid",
"No. Asks",
"No. Bids",
"No. Trades",
"Open",
"Open Ask",
"Open Bid",
"Volume"
],
"IdentifierList": {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
"InstrumentIdentifiers": [{
"Identifier": "FB.O",
"IdentifierType": "Ric"
}],
"UseUserPreferencesForValidationOptions":"false"
},
"Condition": {
"MessageTimeStampIn": "GmtUtc",
"ReportDateRangeType": "Range",
"QueryStartDate": "2020-05-14T00:00:00.000Z",
"QueryEndDate": "2020-05-16T00:00:00.000Z",
"SummaryInterval": "OneHour",
"TimebarPersistence":"true",
"DisplaySourceRIC":"true"
}
}
}
r2 = requests.post(requestUrl, json=requestBody,headers=requestHeaders)
#Display the HTTP status of the response
#Initial response status (after approximately 30 seconds wait) is usually 202
status_code = r2.status_code
print ("HTTP status of the response: " + str(status_code))
0 -
Thanks @veerapath.rungruengrayubkul, that solution worked perfectly and am now able to retrieve the data. Thanks for your help on this
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 690 Datastream
- 1.5K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 560 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 281 Open PermID
- 46 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 724 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛