Hi,

I'm trying to get QuantConnect Lean CLI to connect to Interactive Brokers (IBKR) and download and backtest some option data from last week.

Here's the setup:

   public override void Initialize()
   {
       var endDate = DateTime.Today.AddDays(-1);
       var startDate = endDate.AddDays(-7);
       SetStartDate(startDate);
       SetEndDate(endDate);
       SetCash(100000);
       SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);
       _equity = AddEquity("AAPL", Resolution.Minute).Symbol;
       Securities[_equity].SetDataNormalizationMode(DataNormalizationMode.Raw);
       SetBenchmark(_equity);
       var option = AddOption(_equity, Resolution.Minute);
       option.SetFilter(-3, 3, TimeSpan.FromDays(15), TimeSpan.FromDays(60));
   }

(1) I made sure to have correct data subscriptions with IBKR and that they are active.

- NASDAQ (Network C/UTP) - North America
- NYSE (Network A/CTA) - North America
- NYSE American, BATS, ARCA, IEX, and Regional Exchanges (Network B) - North America
- OPRA (US Options Exchanges) - North America

(2) Market data is shared with the IBKR paper trading account.

(3) Mobile authentication is activated on the account.

(4) After setting up Lean CLI to use IBKR, `lean.json` has the following properties set:

   "data-provider": "QuantConnect.Lean.Engine.DataFeeds.DownloaderDataProvider",
   "ib-account": "<paper trading account>",
   "ib-user-name": "...",
   "ib-password": "...",
   "ib-trading-mode": "paper",
   "id": "InteractiveBrokersBrokerage",
   "data-downloader": "QuantConnect.ToolBox.IBDownloader.IBDataDownloader"

 

(5) Have Researcher Seat subscription with QuantConnect.

(6) I run the algo with the following command:

lean backtest MyProject --data-provider-historical "Interactive Brokers" --backtest-name qc-ibkr-backtest-01


and
(7) authenticate with mobile app:
    TRACE:: InteractiveBrokersBrokerage.OnIbAutomaterOutputDataReceived(): 2FA confirmation success

After running the algo, it shows that the stock data for the last 7 days get downloaded but option data fails to download. Also can confirm that from the downloaded files in the data folder.

From the logs:

DATA USAGE:: Total data requests 62 DATA USAGE:: Succeeded data requests 7 DATA USAGE:: Failed data requests 55


 

There is one error during execution:

20240514 21:08:17.198 TRACE:: InteractiveBrokersBrokerage.LookupSymbols(): Requesting symbol list for AAPL ... 20240514 21:08:17.218 ERROR:: <>c__DisplayClass9_0.b__0(): System.NullReferenceException: Object reference not set to an instance of an object. at QuantConnect.Brokerages.InteractiveBrokers.InteractiveBrokersBrokerage.LookupSymbols(Symbol symbol, Boolean includeExpired, String securityCurrency) at QuantConnect.ToolBox.IBDownloader.IBDataDownloader.GetChainSymbols(Symbol symbol, Boolean includeExpired) at QuantConnect.ToolBox.IBDownloader.IBDataDownloader.Get(DataDownloaderGetParameters dataDownloaderGetParameters) at QuantConnect.Lean.Engine.DataFeeds.DownloaderDataProvider.GetDownloadedData(IEnumerable`1 downloaderDataParameters, Symbol symbol, DateTimeZone exchangeTimeZone, DateTimeZone dataTimeZone, Type dataType)+MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/DownloaderDataProvider.cs:line 220 at QuantConnect.Lean.Engine.DataFeeds.DownloaderDataProvider.<>c__DisplayClass9_0.b__0(String s) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/DownloaderDataProvider.cs:line 178

 

At this point I am blocked and don't know how to fix this. Can you please help?

Thanks,
Omid