Hey, so if I backtest my options algo it works perfectly.  The buy triggers function correctly and the option chain finds and purchases option contracts exactly as expected.  However, when I run the algo live.  The option chain doesn't function.  What is going on here?  The buy trigger is met, the algo tries to run the option chain but then just doesn't purchase anything.

Is it my data feed for the live trading? I'm using quant connect for data.  When I backtest it uses it too.  I dont get why it purchases the options perfectly on backtesting but doesn't even attempt to make the option purchase on live trading.  I'm not missing orders, no orders have been placed.  I have options access on Interactive brokers and when I run the same algo with the option filter method it will purchase the options fine.  Just would prefer to use the option chain as it helps with another aspect of the algo.

 

Tomorrow I'll try to run the algo live with quant and interactive brokers as combined data feeds.  If I run it with just interactive brokers then my results for my consolidated bars on my RSI values aren't correct.

 

In initialize I have the following:

		#QQQ option initialize
        self.equityqqq = self.AddEquity("QQQ", Resolution.Minute)
        self.equityqqq.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.symbolqqq = self.equityqqq.Symbol
		
		self.contractqqq = str()
        self.contractsAddedqqq = set()

for the option chain I have the following code:

def Buyqqqcall(self, data):
        # get option data
        if self.contractqqq == str():
            self.Log("Obtaining QQQ contract")
            self.contractqqq = self.OptionsFilterqqq(data)
            return
        
        # if not invested and option data added successfully, buy option
        if not self.Portfolio[self.contractqqq].Invested and data.ContainsKey(self.contractqqq):
            self.SetHoldings(self.contractqqq, 0.05)
            self.qqqoptionlist[0] = 5
            
         
  
            
            
    def OptionsFilterqqq(self, data):
        ''' OptionChainProvider gets a list of option contracts for an underlying symbol at requested date.
            Then you can manually filter the contract list returned by GetOptionContractList.
            The manual filtering will be limited to the information included in the Symbol
            (strike, expiration, type, style) and/or prices from a History call '''

        contractsqqq = self.OptionChainProvider.GetOptionContractList(self.symbolqqq, data.Time)
        self.underlyingPriceqqq = self.Securities[self.symbolqqq].Price
        # filter the out-of-money put options from the contract list which expire close to self.DTE num of days from now
        qqqotm_calls = [i for i in contractsqqq if i.ID.OptionRight == OptionRight.Call and
                                            i.ID.StrikePrice > self.OTM * self.underlyingPriceqqq and
                                            self.DTE - 4 < (i.ID.Date - data.Time).days < self.DTE + 4]
                                            
        if len(qqqotm_calls) > 0:
            # sort options by closest to self.DTE days from now and desired strike, and pick first
            qqqcontract = sorted(sorted(qqqotm_calls, key = lambda x: abs((x.ID.Date - self.Time).days - self.DTE)),
                                                     key = lambda x: abs(x.ID.StrikePrice - self.underlyingPriceqqq))[0]
            if qqqcontract not in self.contractsAddedqqq:
                self.contractsAddedqqq.add(qqqcontract)
                # use AddOptionContract() to subscribe the data for specified contract
                self.AddOptionContract(qqqcontract, Resolution.Minute)
            return qqqcontract
            self.Log("qqqcontract {0}".format(qqqcontract))
        else:
            return str()

Author