Is there a way to pull all expired contracts for a commodity? The same process is fairly straightforward for active contracts, but I haven't been able to find a simple method for expired contracts. If none exist, is there a means of pulling expiry dates for all active contracts?
Here's an example retrieving all expired CBOT corn futures. The result set contains one incorrect item (CH8). All expired future RICs contain carat symbol (^). You can filter out incorrect item that doesn't contain carat in the RIC name from the result set returned from the search.
rdp.search( view = rdp.SearchViews.CommodityQuotes, filter = ("ExchangeCode eq 'CBT' and AssetCategory eq 'CMF' and " + "PrimaryChainRIC eq '0#C:' and ExpiryDate lt 2021-02-05"), select = "RIC,ExpiryDate", top = 1000)
For more info on using RDP Library to perform various types of searches see the article titled "Building Search into your Application Workflow".