Can't undestand how to access OHLC minute data for futures. Watched this video https://www.quantconnect.com/videos/community-contributed/#uv1phsM2Pgw
but OnTradeBar method is not working.
I tried futures templates but still can't fully understand how to access this information.
Alexandre Catarino
OnTradeBar was deprecated, you need to use OnData instead:
def OnData(self,slice): for chain in slice.FutureChains: # Get contracts expiring no earlier than in 90 days contracts = filter(lambda x: x.Expiry > self.Time + timedelta(90), chain.Value) # if there is any contract, trade the front contract if len(contracts) == 0: continue front = sorted(contracts, key = lambda x: x.Expiry, reverse=True)[0] self.MarketOrder(front.Symbol , 1)
The slice object has the FutureChains object that includes futures contracts for each future you have subscribed to (ES, CL, GC, etc). In the above example, chain.Value are the contracts of a given future. You can use the contract symbol to access OHLC information:
bar = slice[front.Symbol] open = bar.Open high = bar.High low = bar.Low close = bar.Close
Victor Zakharenko
Thank you. Now it is working. I have small bugs in subscription code as well. That's was the point.
Victor Zakharenko
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!