Last Updated: 21 Oct 2021
Overview
LSEG Tick History - REST API is a Representational State Transfer (REST)-compliant API that programmatically exposes Tick History functionality on the DataScope Select platform. Client applications can be written in most programming languages, such as C#, C++, Visual Basic, Java, Python, Objective-C, and Swift.
One of the favorite use cases for applications that use the legacy SOAP-based Tick History API is to use the API to expand a Chain RIC and get a RIC list. After getting the list, they can pass the list to retrieve some specific data using other Tick History functions and they can also export the list to other applications. This article will demonstrate how to use the new REST API to expand a Chain RIC and get a RIC list like the legacy API.
This example demonstrates how to interact with the LSEG Tick HIstory REST API without using.Net SDK. And we use Python programming language to demonstrate the API usages as it works as a script and it can work across OS. This example applies knowledge from Tick History document and tutorial from developer community website.
Introduction
The Legacy SOAP API has the ExpandChain method which will return a list of the RICs for all instruments that were part of the given chain at any time during the given time period. This Function expands the chain for the given RIC independently on each day in the requested range of dates and then collates the results as a single list of RICs. For the new REST API, clients can expand a chain RIC and get underlying RICs using HTTP endpoint /Search/HistoricalChainResolution. The API calls resolve current and past chain constituents given a Chain RIC. Instruments may be currently active, or inactive. It can be very time consuming on both SOAP and REST API. Try not to use this function with large ranges of dates.
HTTP Request
- Endpoint URL:
https://selectapi.datascope.refinitiv.com/RestApi/v1/Search/HistoricalChainResolution
- Method: POST
- Headers:
Prefer: respond-async
Content-Type: application/json; odata.metadata=minimal
Authorization: <Your Authorization Token>
- Body:
ChainRics: Identifies one or more chain RICs, each of which will be resolved into its constituent RICs.
Start: Start date. For example, 2017-01-01T00:00:00.000Z.
End: End date. For example, 2017-01-01T00:00:00.000Z.
- Sample Request Body
 {
    "Request":
        {
           "ChainRics": [ "0#HO:" ],
           "Range": {
              "Start": "2008-01-01T00:00:00.000Z",
              "End": "2016-01-01T00:00:00.000Z"
             }
        }
}
HTTP Response
- Sample Response message
HTTP/1.1 200 OK
 {
  "@odata.context": "https://selectapi.datascope.refinitiv.com/RestApi/v1/$metadata#Collection(DataScope.Select.Api.Search.HistoricalChainInstrument)",
  "value": [
       {
        "Identifier": "0#HO:",
        "IdentifierType": "ChainRIC",
        "Source": "",
        "Key": "VjF8MHgxMDAwMDAwMDAwMDAwMDAwfDB4MTAwMDAwMDAwMDAwMDAwMHx8Q0hSfENIUnxDSFJ8SHx8MCNITzp8",
        "Description": "Historical Chain",
        "InstrumentType": "Unknown",
        "Status": "Valid",
        "Constituents": [
                {      Â
                 "Identifier": "HOF0",
                 "IdentifierType": "Ric",
                 "Source": "", "Key": "VjF8MHgzMDAwMDAwMDAwMDAwMDAwfDB4MzAwMDAwMDAwMDAwMDAwMHx8fHx8fHxIT0YwfA",
                 "Description": "Historical Instrument",
                 "InstrumentType": "Unknown",
                 "Status": "Valid",
                 "DomainCode": "6"
                },
Â
       . . .                                             Â
                {
                 "Identifier": "HOZ9",
                  "IdentifierType": "Ric",
                  "Source": "",
                  "Key": "VjF8MHgzMDAwMDAwMDAwMDAwMDAwfDB4MzAwMDAwMDAwMDAwMDAwMHx8fHx8fHxIT1o5fA",
                  "Description": "Historical Instrument",
                  "InstrumentType": "Unknown",
                  "Status": "Valid",
                  "DomainCode": "6"
                }]
        ]
Â
     }
  ]
}
From the HTTP response, it presents the chain’s constituent RICs. Hence the application has to parse JSON object and get the RIC list by accessing the value of Constituents.
Python Example
Prerequisite
- To run the example user should have python 2.7 or 3.6 installed on OS. A user can download python installer from the link below. Basically, users can open the example with any text editor. There are free Python IDEs such as PyCharm Community edition and Visual Studio Code developers can use to open python source file.
https://www.python.org
- In order to access the Tick History Endpoint, a user must have DSS account with permission to access Tick History’s REST API. Please contact your LSEG Account representative if you need a new account or additional permissions.
- To use HTTP request and response, this example uses the Python 'requests' module.
- This example uses pandas data frames and some functions from numpy to parse and display data so you have to install pandas and numpy module.
Implementation
The example starts from importing the required Python modules so you need to import requests and JSON module to the example. It also requires pandas and numpy module to convert JSON data to the pandas data frame.
from json import dumps, loads, load
from requests import post,get
...
import pandas as pd
import numpy as np
Authentication
To get an Authentication Token, the example will require a valid username and password and then send a new Authentication request to the DSS server to get a new Token. After it gets a new Token, it will pass the token to the Http request header. Below is the code for requesting a new token from the DSS server. If a user doesn’t want to get a new token as the old one still valid for 24 hours, feel free to modify RequestNewToken function to return valid token instead.
def RequestNewToken(username="",password=""):
  _AuthenURL = "https://selectapi.datascope.refinitiv.com/RestApi/v1/Authentication/RequestToken"
  _header= {}
  _header['Prefer']='respond-async'
  _header['Content-Type']='application/json; odata.metadata=minimal'
  _data={'Credentials':{
    'Password':password,
    'Username':username
    }
  }
Â
  print("Send Login request")
  resp=post(_AuthenURL,json=_data,headers=_header)
Â
  if resp.status_code!=200:
    message="Authentication Error Status Code: "+ str(resp.status_code) +" Message:"+resp.text
    raise Exception(dumps(message,indent=4))
Â
  return loads(resp.text)['value']
Expand Chain
Before sending an Http request with a post message to HistoricalChainResolution endpoint, it required the Authorization Token from the previous steps with JSON payload containing Chain RIC, start date and end date. Please find sample JSON payload from section Sample Request Body.
In order to get underlying RICs from HTTP response message(see section Sample Response message), the application has to access the Constituents list from JSON object and then convert the list to a pandas data frame. And then it can access RIC list under the Constituents list. Below is the python code from the example. It will print a data frame containing RIC name and Status to console.
def ExpandChain(token,json_payload):
  _expandChainURL = "https://selectapi.datascope.refinitiv.com/RestApi/v1/Search/HistoricalChainResolution"
  _header = {}
  _header['Prefer'] = 'respond-async'
  _header['Content-Type'] = 'application/json; odata.metadata=minimal'
  _header['Accept-Charset'] = 'UTF-8'
  _header['Authorization'] = 'Token' + token
  resp = post(_expandChainURL, data=None, json=json_payload, headers=_header)
  item_list = []
  if(resp.status_code==200):
    json_object=loads(resp.text,object_pairs_hook=OrderedDict)
    if len(json_object['value']) > 0:
      dataFrame = pd.DataFrame.from_dict(json_object['value'][0]['Constituents'])
    else:
      return pd.DataFrame()
  else:
    print("Unable to expand chain response return status code:",resp.status_code)
Â
  return dataFrame
#In the Main function
      _jsonquery={
            "Request": {
              "ChainRics": [
                  _chainRIC
                  ],
              "Range": {
                "Start": _startDate,
                "End": _endDate
              }
             }
      }
      print("Start Expanding Chain "+_chainRIC+"\n")
      df=ExpandChain(_token,_jsonquery)
      if df.empty:
        print("Unable to expand chain "+_chainRIC)Â
        return
Â
      ricCount=len(df['Identifier'])
      print("Found "+str(ricCount)+" RIC")
      #Filter and print only RIC name and Status columns
      pd.set_option('display.max_rows', ricCount)
      newDF = df.filter(items=['Identifier','Status'])
      newDF.index = np.arange(1,len(newDF)+1)
      print(newDF)
Running example
To test the example, please run the following python command
>python ExpandChainREST.py
The example will ask a user to input DSS username and password then it will request a new Token and pass it to HTTP request as described. Feel free to change the following variables if you want to set chain RIC, start date, end date.
_chainRIC="0#.FTSE"
_startDate="2017-03-14T00:00:00.000Z"
_endDate="2017-03-15T00:00:00.000Z"
After running the example, it will display the following console output
Login to DSS Server
Send Login request
Authorization Token:_tHSMJfR5k2n4a56GCmGhhyCCYjt1AA6F5FC3DswB9ad55M5TQhpkOuK6jw5NWy3ir9Vzq5phjQ71rHkZhYrB7tA0c6eBEAVDlOK26H98YWYe9QqVSYp-5IeaMsI9QYIvB-ZxQr5xEv1Mc6u1KF9Afzbq3LtSC11qALNdIIS4JbGjNLqKJ8HgTD6VYuUa6Vc-OlXvEkIlClkUH7_tLCKNwqNZZYK7LPFxnhXWq9NhsoxAoxMOj2kRM1NnhUoCIIgOYfkyw69GEMTauLoHLyOHprN_4KsDlBQN59BQ8OAQu5c
Â
Start Expanding Chain 0#.FTSE
Â
Found 103 RIC
  Identifier Status
1Â Â Â .AD.FTSEÂ Valid
2Â Â Â Â .FTSEÂ Valid
3Â Â Â Â AAL.LÂ Valid
4Â Â Â Â ABF.LÂ Valid
5Â Â Â Â ADML.LÂ Valid
6Â Â Â Â AHT.LÂ Valid
7Â Â Â Â ANTO.LÂ Valid
8Â Â Â Â Â AV.LÂ Valid
9Â Â Â Â AZN.LÂ Valid
10Â Â Â Â BAB.LÂ Valid
11Â Â Â BAES.LÂ Valid
12Â Â Â BARC.LÂ Valid
13Â Â Â BATS.LÂ Valid
14Â Â Â BDEV.LÂ Valid
15Â Â Â BLND.LÂ Valid
16Â Â Â Â BLT.LÂ Valid
17Â Â Â BNZL.LÂ Valid
18Â Â Â Â BP.LÂ Valid
19Â Â Â BRBY.LÂ Valid
20Â Â Â Â BT.LÂ Valid
21Â Â Â Â CCH.LÂ Valid
22Â Â Â Â CCL.LÂ Valid
23Â Â Â Â CNA.LÂ Valid
24Â Â Â Â CPG.LÂ Valid
25Â Â Â CRDA.LÂ Valid
26Â Â Â Â CRH.LÂ Valid
27Â Â Â CTEC.LÂ Valid
28Â Â Â Â DCC.LÂ Valid
29Â Â Â Â DGE.LÂ Valid
30Â Â Â DLGD.LÂ Valid
31Â Â Â EXPN.LÂ Valid
32Â Â Â Â EZJ.LÂ Valid
33Â Â Â FRES.LÂ Valid
34Â Â Â Â GKN.LÂ Valid
35Â Â Â GLEN.LÂ Valid
36Â Â Â Â GSK.LÂ Valid
37Â Â Â Â HIK.LÂ Valid
38Â Â Â HMSO.LÂ Valid
39Â Â Â HRGV.LÂ Valid
40Â Â Â HSBA.LÂ Valid
41Â Â Â ICAG.LÂ Valid
42Â Â Â Â IHG.LÂ Valid
43Â Â Â Â III.LÂ Valid
44Â Â Â Â IMB.LÂ Valid
45Â Â Â Â INF.LÂ Valid
46Â Â Â INTUP.LÂ Valid
47Â Â Â ITRK.LÂ Valid
48Â Â Â Â ITV.LÂ Valid
49Â Â Â JMAT.LÂ Valid
50Â Â Â Â KGF.LÂ Valid
51Â Â Â LAND.LÂ Valid
52Â Â Â LGEN.LÂ Valid
53Â Â Â LLOY.LÂ Valid
54Â Â Â Â LSE.LÂ Valid
55Â Â Â MCRO.LÂ Valid
56Â Â Â MDCM.LÂ Valid
57Â Â Â MERL.LÂ Valid
58Â Â Â Â MKS.LÂ Valid
59Â Â Â MNDI.LÂ Valid
60Â Â Â Â MRW.LÂ Valid
61Â Â Â Â NG.LÂ Valid
62Â Â Â Â NXT.LÂ Valid
63Â Â Â Â OML.LÂ Valid
64Â Â Â Â PFG.LÂ Valid
65Â Â Â Â PPB.LÂ Valid
66Â Â Â Â PRU.LÂ Valid
67Â Â Â Â PSN.LÂ Valid
68Â Â Â PSON.LÂ Valid
69Â Â Â Â RB.LÂ Valid
70Â Â Â Â RBS.LÂ Valid
71Â Â Â RDSa.LÂ Valid
72Â Â Â RDSb.LÂ Valid
73Â Â Â Â REL.LÂ Valid
74Â Â Â Â RIO.LÂ Valid
75Â Â Â Â RMG.LÂ Valid
76Â Â Â Â RR.LÂ Valid
77Â Â Â Â RRS.LÂ Valid
78Â Â Â Â RSA.LÂ Valid
79Â Â Â Â RTO.LÂ Valid
80Â Â Â SBRY.LÂ Valid
81Â Â Â Â SDR.LÂ Valid
82Â Â Â Â SGE.LÂ Valid
83Â Â Â Â SHP.LÂ Valid
84Â Â Â Â SJP.LÂ Valid
85Â Â Â Â SKG.LÂ Valid
86Â Â Â SKYB.LÂ Valid
87Â Â Â Â SL.LÂ Valid
88Â Â Â SMIN.LÂ Valid
89Â Â Â Â SMT.LÂ Valid
90Â Â Â Â SN.LÂ Valid
91Â Â Â Â SSE.LÂ Valid
92Â Â Â STAN.LÂ Valid
93Â Â Â Â SVT.LÂ Valid
94Â Â Â TSCO.LÂ Valid
95Â Â Â TUIT.LÂ Valid
96Â Â Â Â TW.LÂ Valid
97Â Â Â ULVR.LÂ Valid
98Â Â Â Â UU.LÂ Valid
99Â Â Â Â VOD.LÂ Valid
100Â Â Â WOS.LÂ Valid
101Â Â Â WPG.LÂ Valid
102Â Â Â WPP.LÂ Valid
103Â Â Â WTB.LÂ Valid
Note
The time to expand chain is proportional to the number of days in the date range. Do not specify longer date ranges than necessary.
Source Code Downloads
The sources code can be downloaded from ExpandChain
Downloads