Also IB Gateway version 978 seems stable and reconnects seemingly better than the older versions like 972. It also has a "log in once a week" feature, that works. If you're on foreign IB site like Canada's 972 is all it offers. Download 978 (the most recent version) from the US site.
I discovered your good tool backtrader_addons & start using it. I found a 'ZeroDivisionError: float division by zero' bug when there is no trade in a test.
Below are the stacktrace for your reference.
Traceback (most recent call last):
File "C:/Users/john/PycharmProjects/Backtrader/venv/Include/IBPaperTrade.py", line 83, in <module>
strats = cerebro.run(tradehistory=True) # for trade_list
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\cerebro.py", line 1301, in runstrategies
TestStrategy, Bracket, 2020-06-04-030233, Strategies execution completed 0 trade with self.broker.cash=7788592.0392 and self.broker.getvalue()=7788591.99
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\strategy.py", line 486, in _stop
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader\analyzer.py", line 200, in _stop
File "C:\Users\john\PycharmProjects\Backtrader\venv\lib\site-packages\backtrader_addons-0.18.10-py3.6.egg\backtrader_addons\analyzers\limited_test_report.py", line 80, in stop
self.rpt['win_percent'] = 100.0 * win_percent / len(trades)
ZeroDivisionError: float division by zero
There is no need for logic there and that's why there is none. The entry order (aka main side) is protected automatically with a stop-loss side and a take-profit side (the high/low side depends on the direction entry), which are only active if the entry order is executed.
Once the stop-loss/take-profit sides become active, the execution of any of them automatically cancels the other.
If you decide to exit the market with an unrelated order, you have to manually cancel any of the sides (the other will be cancelled automatically) as in
self.cancel(order_stop_loss_side) # this automatically cancels the take-profit side too
I have discovered the problem. It is not related to Backtrader.
I did some digging around on the IB website. It seems that the IB demo account does not allow historical bars through the API for anything other than FOREX. The same applies to paper trading or live accounts unless there is a subscription to the relevant market data feed. If there is a subscription in place then the historical bars are available at any time, including week-ends.
(As an aside, historical bars are constructed by TWS regardless of whether there is a subscription in place or not.)
Delayed data is available during market hours for accounts without market data subscription, but to obtain this data a flag has to be set in the API. I don't think Backtrader allows the user to set this flag but I have not investigated this in detail.