question

Upvotes
Accepted
3 0 1 3

Tick History in R language

I'm trying to use Tick History via R following instructions in web pages below.

https://developers.thomsonreuters.com/article/tick-history-r-language-part-1?sh=1

https://developers.thomsonreuters.com/article/tick-history-r-language-part-1?sh=2

https://developers.thomsonreuters.com/article/tick-history-r-language-part-1?sh=3

I tried to extract tick data through commands below. However, the response shows <EMPTY BODY> and status = 202. I think I successfully logged in and got a proper token using functions in

https://github.com/TR-API-Samples/Article.TRTH.R.TRTHinR/blob/master/R/TRTH.R.

b = '{

"ExtractionRequest": {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.TickHistoryTimeAndSalesExtractionRequest",
"ContentFieldNames": [
"Trade - Price"
],
"IdentifierList": {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList", 
"InstrumentIdentifiers": [
{
"Identifier": "JNIc1",
"IdentifierType": "Ric"
}]
},
"Condition": {
"MessageTimeStampIn": "GmtUtc",
"ReportDateRangeType": "Range",
"QueryStartDate": "2017-09-29T00:00:00.000Z",
"QueryEndDate": "2017-09-29T00:00:00.010Z"
}
}
}'

url <- "https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/ExtractRaw"
token <- get("token",envir = cacheEnv)

r <- httr::POST(url,add_headers(prefer = "respond-async",Authorization = token), content_type_json(),body = b,encode = "json")
tick-history-rest-apir
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
4.4k 10 6 9

Hi @SATO4

Status 202 means Tick History has accepted your extraction request but still processing it.

Tick History will give the URI for monitoring the process. The URI is in the header of the return message.

If you check the code on github, you will see that it check for status 202 and return the URI

if (status_code(r) == 202)
{
message("The request has been accepted but has not yet completed executing asynchronously.\r\nReturn monitor URL\r\n",r$headers$location)
return(invisible(r$headers$location))
}

You have to poll the extraction status until the status is 200.

TRTHCheckRequestStatus <- function(location,path,overwrite = FALSE)
{
token <- get("token",envir = cacheEnv)
r <- GET(location,add_headers(prefer = "respond-async",Authorization = token))
if (status_code(r) == 202)
{
message("The request has not yet completed executing asynchronously.\r\nPlease wait a bit and check the request status again.\r\n")
return(invisible(r$headers$location))
}
else if(status_code(r) == 200)
{
a<-content(r, "parsed", "application/json", encoding="UTF-8")
message(a$Notes)
return(TRTHRawExtractionResults(a$JobId,path,overwrite)) #Extract the data
}
else
{
warn_for_status(r)
a<-content(r, "parsed", "application/json", encoding="UTF-8")
return(a)
}
}
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 1 3

Hi Warat B.

I successfully got some data thanks to your suggestion.

Thank you.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.