hi,
I would like to get all rics of chain of chain 0#LCO++ in python
in 0#LCO++ , you have other chain 0#LCOc1++,0#LCOc2++,0#LCOc3++ , …..
how can I get rics under each chains using a function from 0#LCO++?
Hi @taya.mahendrarajah01, Thank you for your question! Below is one of the methods I could think of.
To get all the RICs from a chain of chains such as 0#LCO++, you can start by retrieving the first‑level constituents. In LSEG Data Library for Python, a chain is treated as just another instrument, so you can load it using ld.get_data().
Step 1 - Get the constituents of the main chain (0#LCO++):
Note: DSPLY_NAME field is real-time field. TR.* field would not help in this case.
import lseg.data as ld import time ld.open_session() chain_1 = ld.get_data( universe=["0#LCO++"],fields=["DSPLY_NAME'] ) first_level_rics = chain_1.Instrument.to_list() print(first_level_rics)
Step 2 - Loop through each sub‑chain to get their constituents:
all_constituents = {} for ric in first_level_rics: try: data = ld.get_data(universe=[ric], fields=["DSPLY_NAME"]) all_constituents[ric] = data.Instrument.to_list() # Add delay (e.g., 0.5 seconds) to control throttling time.sleep(0.5) except Exception as e: print(f"Error reading {ric}: {e}") time.sleep(0.5) # also delay between errors
This will collect all the RICs under each of the sub‑chains.
Note on errors: You may notice that some chain RICs like 0#LCOc66++ return errors. This usually means:
These situations require validation on the content side, so if a particular RIC consistently fails, you can raise a ticket with LSEG Support to check the chain definition as we are not the content experts.
Hope this helps. Please continue on this thread if you need help further.
Thank you :)
@taya.mahendrarajah01
Another option could be the Search API. For more information, please refer to the Building Search into your Application Workflow article.
For example:
df = ld.discovery.search( view = ld.discovery.Views.SEARCH_ALL, filter = "RicRoot eq 'LCO' and UnderlyingRCSAssetClass eq 'FUT' and IsChain eq false and AssetStateName eq 'Active' and RCSAssetCategoryLeaf eq 'Commodity Future Option'", top=10000) df
It returns 12822 entries which exceed the API limit so I need to add another filter to limit the number of entries per each call. I used the StrikePrice. For example:
df = ld.discovery.search( view = ld.discovery.Views.SEARCH_ALL, filter = ("RicRoot eq 'LCO' " "and UnderlyingRCSAssetClass eq 'FUT' " "and IsChain eq false " "and AssetStateName eq 'Active' " "and RCSAssetCategoryLeaf eq 'Commodity Future Option' " "and StrikePrice lt 90"), top=10000) display(df) df1 = ld.discovery.search( view = ld.discovery.Views.SEARCH_ALL, filter = ("RicRoot eq 'LCO' " "and UnderlyingRCSAssetClass eq 'FUT' " "and IsChain eq false " "and AssetStateName eq 'Active' " "and RCSAssetCategoryLeaf eq 'Commodity Future Option' " "and StrikePrice ge 90"), top=10000) display(df1)
You can contact the helpdesk support team directly via LSEG Support to refine the search filter.