question

Upvotes
Accepted
5 0 1 7

Some FuturesAndOptionsSearch requests do not return metadata for futures contracts

I am iterating through rics in a futures chain to get the metadata on each contract. However, some of these rics are returning metadata and others are not. What is the cause of this?


requestUrlChain = "https://selectapi.datascope.refinitiv.com/RestApi/v1/Search/HistoricalChainResolution"
requestUrlFut = "https://selectapi.datascope.refinitiv.com/RestApi/v1/Search/FuturesAndOptionsSearch"

requestBody={
   "Request": {
          "ChainRics": ["0#FCE:"],
      "Range": {
          "Start": "2020-06-12T00:00:00.000Z",
          "End": "2021-06-12T00:00:00.000Z"
      }
  }
}


r2 = requests.post(requestUrlChain, json=requestBody,headers=requestHeaders)

status_code = r2.status_code
if status_code == 200 :
    r2Json = json.loads(r2.text.encode('ascii', 'ignore'))
    json_formatted_str = json.dumps(r2Json['value'][0]['Constituents'], indent=2)


    for id in r2Json['value'][0]['Constituents']:
        # futures search 
        requestBody={
            "SearchRequest": {
                "IdentifierType": "Ric",
                "Identifier": id['Identifier'] #"FCEK1"
            }
        }

        r3 = requests.post(requestUrlFut, json=requestBody,headers=requestHeaders)
        status_code = r3.status_code

        if status_code == 200 :
            r3Json = json.loads(r3.text.encode('ascii', 'ignore'))
            json_formatted_str = json.dumps(r3Json, indent=2)
            print('RIC: '+id['Identifier'])
            print(json_formatted_str) 


Attached images show some output1656344208721.png


1656344238605.png

pythonpython apifutures
1656344208721.png (96.8 KiB)
1656344238605.png (72.5 KiB)
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.

hi @pdebaz ,

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?
If so please can you click the 'Accept' text on the left side of the appropriate reply? This will guide all community members who have a similar question.

Thanks,
AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,


AHS


Upvote
Accepted
5.8k 21 2 6

Hi @pdebaz,


I'd strongly suggest using RD and reading this article. I used it in writing the below example of a way to find the RICs you're after programmatically:


Eg.1: The code below requests M&A data using filters and orders the data by the announcement date in descending order. For more info on filters, please log into the API Playground and and then see the documentation here.

MnA  = search.Definition(
    view = search.SearchViews.DEALS_MERGERS_AND_ACQUISITIONS,  # for info on `SearchViews`, you can use `help(search.SearchViews)`
    
    # specify filtering properties
    filter = "((AcquirerCompanyName ne 'Creditors' and AcquirerCompanyName ne 'Shareholder') and (TargetCountry eq 'US' or TargetCountry eq 'UK')"
    + "and TransactionValueIncludingNetDebtOfTarget ge 100 and TargetPublicStatus eq 'Public')"
    + "and (TransactionStatus eq 'Completed' or TransactionStatus eq 'Pending' or TransactionStatus eq 'Withdrawn')"
    + "and (FormOfTransactionName xeq 'Merger' or FormOfTransactionName xeq 'Acquisition') and (TransactionAnnouncementDate le 2021-11-15 and TransactionAnnouncementDate ge 2020-09-15)",
    
    # # select only the required fields and order them based on announcement date
    # # then specify number of items to be 10000, default value is 100
    select = 'TransactionAnnouncementDate, TargetCompanyName, TargetRIC',
    order_by = 'TransactionAnnouncementDate desc',
    top = 100
).get_data()
MnA = MnA.data.df
MnA 

1656513884526.png


Eg.2: Searching programmatically for 'FCEM0':

import refinitiv.data as rd# !pip install refinitiv-data
rd.open_session(config_name="C:\\Example.DataLibrary.Python-main\\Configuration\\refinitiv-data.custom.config.json")
rd.open_session("platform.rdp")
from refinitiv.data.content import search
testSearch  = search.Definition(
    view = search.SearchViews.SEARCH_ALL,  # for info on `SearchViews`, you can use `help(search.SearchViews)`
    query = "FCEM0"
).get_data().data.df
testSearch


1656514324640.png


An example of the refinitiv-data.custom.config.json file can be found here.



1656513884526.png (38.6 KiB)
1656514324640.png (11.6 KiB)
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.

Hi Mr. Legrande. I'm trying to do as you suggest.


When I try to establish a session, I get the response:

1656530352528.png


My Config:

{
    "sessions": {
        "default": "platform.my-custom-session",
        "platform": {
            "my-custom-session": {
                "app-key": "APPKEY",
                "username": "USERNAME",
                "password": "[PASSWORD]"
            }
        }
    }
}
 


I know the username/pw are correct because if I request an auth token with them via a POST to RequestToken then I do get one.

What do you advise?


1656530352528.png (7.2 KiB)

Hi @pdebaz ,


Have you tried entering the absolute path of the config file in the session opening line?

E.g.

rd.open_session(config_name="C:\\Example.DataLibrary.Python-main\\Example.DataLibrary.Python-main\\Configuration\\refinitiv-data.custom.config.json")
rd.open_session("platform.rdp")
Upvotes
5.8k 21 2 6

Hi @pdebaz ,


Can you find such data in Workspace where none is returned in your call desribed here?

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.

Here is an example with the treasury bond futures:

First, you can see the RIC being returned by a chain search and the metadata return empty

1656350599272.png



Finally, a screengrab from the workspace search... i don't see any exact matches, but i have not used this before
1656350481499.png

1656350481499.png (148.6 KiB)
1656350599272.png (50.7 KiB)
Upvote
5.8k 21 2 6

Hi @pdebaz ,


It looks like, in your request, you're asking for info on RICs that don't exist. I believe that it's because they're for contracts that might have expired, after which time thei RICs change. E.g.: in your 1st screenshots on Jun 27th, you were requesting data on 'FCEM0' where no such RIC exists; however, there is FCEM0^1 and FCEM0^2


capture.png


Do let me know if FCEM0^1 was the one you were actually after.

If the issue is now changed such that you would be looking for these search results shown in my screenshot, to find the RICs you are after; please note that you can use the search API to find those RICs, even if they are slightly different to what was expected. I wrote a piece of code that uses that functionality here in another use case. Do let me know if this is what you were after, or if it isn't, in which case I'll continue investigating.


capture.png (41.4 KiB)
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.

Hi Mr. Legrand. I think you are on the right track here. I am trying to find all historical and forward contracts in a chain and I was unaware of the ^1 ^2 style modifiers. I wonder why HistoricalChainResolution does not return these RICs. Regardless, I think this is the way to proceed. How do I get the correct RICs? I have to admit your linked code is confusing me a bit. Is there a simple request body you can indicate? Thank you.

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.