Last update | Dec 2023 |
Environment | Any |
Language | Any HTTP is supported |
Compilers | None |
Prerequisites | DSS login, internet access, REST API Tutorial 3 |
Source code | Below |
Please follow the previous tutorial, which explains the workflow, before going through this one.
This tutorial explains how to retrieve historical tick data, also called time and sales data, with an On Demand extraction request, using the following steps:
This step is optional. If you do not know what content field names are available, you can request a list of those available.
URL:
The available field set depends on the type of data you want to request. The data type must therefore be specified in the request, which is done by setting a report template type in the URL. As we want tick data we set a value of TickHistoryTimeAndSales. The following tutorials show other possibilities.
https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/GetValidContentFieldTypes(ReportTemplateType=DataScope.Select.Api.Extractions.ReportTemplates.ReportTemplateTypes'TickHistoryTimeAndSales')
Method: GET
Headers:
Note: for all requests we need a user token, set in the header. The token was retrieved in Tutorial 1.
Prefer: respond-async
Content-Type: application/json
Authorization: Token F0ABE9A3FFF2E02E10AE2765ED872C59B8CC3B40EBB61B30E295E71DE31C254B8648DB9434C2DF9299FDC668AA123501F322D99D45C8B93438063C912BC936C7B87062B0CF812138863F5D836A7B31A32DCA67EF07B3B50B2FC4978DF6F76784FDF35FCB523A8430DA93613BC5730CDC310D4D241718F9FC3F2E55465A24957CC287BDEC79046B31AD642606275AEAD76318CB221BD843348E1483670DA13968D8A242AAFCF9E13E23240C905AE46DED9EDCA9BB316B4C5C767B18DB2EA7ADD100817ADF059D01394BC6375BECAF6138C25DBA57577F0061
Content-Type: application/json; charset=utf-8
Body:
There are more than 300 values in the response. Here is the beginning of the response:
{
"@odata.context": "https://selectapi.datascope.refinitiv.com/RestApi/v1/$metadata#ContentFieldTypes",
"value": [
{
"Code": "THT.Auction - Exchange Time",
"Name": "Auction - Exchange Time",
"Description": "Exchange supplied exchange time (Local or GMT depending on the exchange).",
"FormatType": "Text",
"FieldGroup": "Auction"
},
{
"Code": "THT.Auction - Price",
"Name": "Auction - Price",
"Description": "Auction Price.",
"FormatType": "Number",
"FieldGroup": "Auction"
},
{
"Code": "THT.Auction - Qualifiers",
"Name": "Auction - Qualifiers",
"Description": "Trade qualifiers or market condition indicator; See Qualifiers for more details.",
"FormatType": "Text",
"FieldGroup": "Auction"
},
{
"Code": "THT.Auction - Sequence Number",
"Name": "Auction - Sequence Number",
"Description": "An exchange derived sequence number associated with the auction (applicable to US markets).",
"FormatType": "Number",
"FieldGroup": "Auction"
},
{
"Code": "THT.Auction - Volume",
"Name": "Auction - Volume",
"Description": "Auction Volume.",
"FormatType": "Number",
"FieldGroup": "Auction"
},
This goes on with all the other available fields. Here is the last part:
{
"Code": "THT.Trade - Volume",
"Name": "Trade - Volume",
"Description": "Last traded volume",
"FormatType": "Number",
"FieldGroup": "Trade"
},
{
"Code": "THT.Trade - Weak Market",
"Name": "Trade - Weak Market",
"Description": "Market weakness",
"FormatType": "Number",
"FieldGroup": "Trade"
},
{
"Code": "THT.Trade - Yield",
"Name": "Trade - Yield",
"Description": "An update to indicate Dividend Yield as adjusted by the last trade or closing price",
"FormatType": "Number",
"FieldGroup": "Trade"
}
]
}
The result contains the field code, name, a description, field type (number, text, date) and group.
The group classifies fields by record type (auctions, corrections, market conditions, quotes and trades). It is preferable not to mix record types in a request.
Choose the field names you want. In the next step we will make a request for trade data, using a small set of these data field names.
This is an On Demand extraction request.
URL:
https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ExtractRaw
Method: POST
Headers:
Prefer: respond-async
Content-Type: application/json
Authorization: Token F0ABE9A3FFF2E02E10AE2765ED872C59B8CC3B40EBB61B30E295E71DE31C254B8648DB9434C2DF9299FDC668AA123501F322D99D45C8B93438063C912BC936C7B87062B0CF812138863F5D836A7B31A32DCA67EF07B3B50B2FC4978DF6F76784FDF35FCB523A8430DA93613BC5730CDC310D4D241718F9FC3F2E55465A24957CC287BDEC79046B31AD642606275AEAD76318CB221BD843348E1483670DA13968D8A242AAFCF9E13E23240C905AE46DED9EDCA9BB316B4C5C767B18DB2EA7ADD100817ADF059D01394BC6375BECAF6138C25DBA57577F0061
Body:
The body of the request must mention it is an extraction request. It contains several parts:
{
"ExtractionRequest": {
"@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.TickHistoryTimeAndSalesExtractionRequest",
"ContentFieldNames": [
"Trade - Price",
"Trade - Volume",
"Trade - Exchange Time"
],
"IdentifierList": {
"@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
"InstrumentIdentifiers": [
{ "Identifier": "CARR.PA", "IdentifierType": "Ric" }
]
},
"Condition": {
"MessageTimeStampIn": "GmtUtc",
"ApplyCorrectionsAndCancellations": false,
"ReportDateRangeType": "Range",
"QueryStartDate": "2016-09-29T00:00:00.000Z",
"QueryEndDate": "2016-09-29T12:00:00.000Z",
"DisplaySourceRIC": true
}
}
}
The possible responses are described in detail the previous tutorial.
In a nutshell, the most likely outcome is a response with an HTTP status of 202 Accepted, and the header will contain a location URL. The next step is to check the request status by polling the location URL regularly until it returns a 200 OK.
If the request is for a small amount of data, the response could have an HTTP status of 200 OK, and the body will contain a jobId and Notes. If the Notes contain the message: Processing completed successfully, we can proceed further. We skip the step where we check the request status, and go directly to the last step, which is to retrieve the data using the jobId.
Other HTTP status codes can be encountered, follow this link for a full list with detailed explanations. It is strongly recommended that your code handle all possible status codes.
Skip this step if the previous step returned an HTTP status of 200 OK.
If the previous step returned an HTTP status of 202 Accepted, this step must be executed, and repeated in a polling loop until it returns an HTTP status of 200 OK.
URL:
This is the location URL, taken from the 202 response header received in the previous step.
https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ExtractRawResult(ExtractionId='0x05a64ba76a4b3036')
Method: GET
Headers:
Prefer: respond-async
Content-Type: application/json
Authorization: Token F0ABE9A3FFF2E02E10AE2765ED872C59B8CC3B40EBB61B30E295E71DE31C254B8648DB9434C2DF9299FDC668AA123501F322D99D45C8B93438063C912BC936C7B87062B0CF812138863F5D836A7B31A32DCA67EF07B3B50B2FC4978DF6F76784FDF35FCB523A8430DA93613BC5730CDC310D4D241718F9FC3F2E55465A24957CC287BDEC79046B31AD642606275AEAD76318CB221BD843348E1483670DA13968D8A242AAFCF9E13E23240C905AE46DED9EDCA9BB316B4C5C767B18DB2EA7ADD100817ADF059D01394BC6375BECAF6138C25DBA57577F0061
If you receive an HTTP status 202 Accepted response (the same as in the previous step), it means the request has not yet completed. You must wait a bit and check the request status again.
If you receive an HTTP status 200 OK response, the body will contain a jobId and Notes. If the Notes contain the message: Processing completed successfully, we can proceed further. We go to the last step, which is to retrieve the data using the jobId.
It is mandatory to have received a 200 OK response with a JobID from a previous step before proceeding with this last step.
URL:
Note the jobId value used as parameter in the URL:
https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/RawExtractionResults('0x05a64ba76a4b3036')/$value
Method: GET
Headers:
Prefer: respond-async
Content-Type: Accept-Encoding: gzip, deflate
Authorization: Token F0ABE9A3FFF2E02E10AE2765ED872C59B8CC3B40EBB61B30E295E71DE31C254B8648DB9434C2DF9299FDC668AA123501F322D99D45C8B93438063C912BC936C7B87062B0CF812138863F5D836A7B31A32DCA67EF07B3B50B2FC4978DF6F76784FDF35FCB523A8430DA93613BC5730CDC310D4D241718F9FC3F2E55465A24957CC287BDEC79046B31AD642606275AEAD76318CB221BD843348E1483670DA13968D8A242AAFCF9E13E23240C905AE46DED9EDCA9BB316B4C5C767B18DB2EA7ADD100817ADF059D01394BC6375BECAF6138C25DBA57577F0061
Content-Encoding: gzip
Content-Type: text/plain
Body:
Here is the beginning of the response content, which for the above query contains more than 2000 lines:
#RIC,Alias Underlying RIC,Domain,Date-Time,GMT Offset,Type,Price,Volume,Exch Time
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,63,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,64,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,27,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,2115,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,21,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,21,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.663334842Z,+2,Trade,23.25,11,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.664006387Z,+2,Trade,23.25,61,07:00:11.033000000
CARR.PA,,Market Price,2016-09-29T07:00:11.664006387Z,+2,Trade,23.25,235,07:00:11.033000000
Here is the end of the response content:
CARR.PA,,Market Price,2016-09-29T09:58:40.317390181Z,+2,Trade,23.315,106,09:58:40.270000000
CARR.PA,,Market Price,2016-09-29T09:59:19.166144512Z,+2,Trade,23.31,291,09:59:19.118000000
CARR.PA,,Market Price,2016-09-29T09:59:38.569569939Z,+2,Trade,23.31,104,09:59:38.522000000
CARR.PA,,Market Price,2016-09-29T09:59:59.561625634Z,+2,Trade,23.305,88,09:59:59.499000000
CARR.PA,,Market Price,2016-09-29T09:59:59.589593409Z,+2,Trade,23.305,200,09:59:59.530000000
CARR.PA,,Market Price,2016-09-29T09:59:59.591582124Z,+2,Trade,23.31,267,09:59:59.530000000
CARR.PA,,Market Price,2016-09-29T09:59:59.591582124Z,+2,Trade,23.31,154,09:59:59.530000000
CARR.PA,,Market Price,2016-09-29T09:59:59.591582124Z,+2,Trade,23.31,275,09:59:59.530000000
CARR.PA,,Market Price,2016-09-29T09:59:59.601791962Z,+2,Trade,23.305,146,09:59:59.543000000
CARR.PA,,Market Price,2016-09-29T09:59:59.637818164Z,+2,Trade,23.305,88,09:59:59.580000000