Getting daily historical through Interactive Brokers (IB)
I have been following the Medium article Interactive Brokers in Python with backtrader and have been able to resample Minutes data to get hourly bars.
However, I am having some trouble getting daily bars.
Here's the code I'm running:
_TICKER = "TSLA-STK-SMART-USD" # "AAPL-STK-SMART-USD" _FROMDATE = datetime.datetime(2021,1,4) _TODATE = datetime.datetime(2021,1,8) datetime.datetime(2019, 9, 25) def run(args=None): cerebro = bt.Cerebro(stdstats=False) store = ibstore.IBStore(host="127.0.0.1", port=7497, clientId= _CLIENTID ) cerebro.broker = store.getbroker() stockkwargs = dict( timeframe=bt.TimeFrame.Days, compression=1, rtbar=False, # use RealTime 5 seconds bars historical=True, # only historical download qcheck=0.5, # timeout in seconds (float) to check for events fromdate=_FROMDATE, # get data from.. todate=_TODATE, # get data to.. latethrough=False, # let late samples through tradename=None # use a different asset as order target ) data0 = store.getdata(dataname=_TICKER, **stockkwargs) cerebro.resampledata(data0, timeframe=bt.TimeFrame.Days, ) cerebro.addstrategy(St) cerebro.run()
I was expecting it to give me four daily bars from 1/4/21 to 1/7/21, but instead, I get two bars:
TWS Time at connection:20210215 11:17:01 EST ***** DATA Notification: DELAYED DEBUG:__main__:1,2021-01-06T00:00:00,709.00,744.49,709.00,733.60,334298.00 DEBUG:__main__:2,2021-01-08T00:00:00,748.00,774.00,746.66,763.60,307274.00 ***** DATA Notification: DISCONNECTED
I have tried hourly bars but the resample gives me the same skip.
stockkwargs = dict( timeframe=bt.TimeFrame.Minutes, compression=60,
Please tell me what I should do to get daily bars.