For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Idiomatic way for adding multiple ibstore live data with different resampling and the same backfill start date



  • Hello

    Suppose I want live data for a same security in 4 different timeframes: 1 minute, 15 minutes, 1 hour and 1 day, and trade on the smallest granular data which is 1 minute bar. I also need to backfill from a specific historical start date to make sure good indicator values coming out from the daily bars. To make sure I don't miss any good minute bar data, the smallest granular data source is 20 seconds bar with "qcheck=2" and "rtbar=True". Is below idiomatic way to do it? Do I have to specify "fromdate" argument for every "ibstore.getdata(...)" line?

    Many thanks.

    Kevin

    data0= ibstore.getdata('FOO', timeframe=bt.TimeFrame.Seconds, compression=20, 
                        rtbar=True,
                        qcheck =2,
                        fromdate=datetime.datetime(2018,9,1) )
    
    min_bar= cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes,compression=1,name='min_bar')
    
    data1= ibstore.getdata('FOO', timeframe=bt.TimeFrame.Minutes,  compression=15,
                        fromdate=datetime.datetime(2018,9,1))    
    
    quarter_bar= cerebro.resampledata(data1, timeframe=bt.TimeFrame.Minutes,
                        compression=15,name='quarter_bar')    
    
    data2= ibstore.getdata('FOO', timeframe=bt.TimeFrame.Minutes,  compression=60, 
                        fromdate=datetime.datetime(2018,9,1))    
    
    hr_bar= cerebro.resampledata(data2, timeframe=bt.TimeFrame.Minutes,
                        compression=60,name='hr_bar')    
    
    data3=ibstore.getdata(data2,timeframe=bt.TimeFrame.Days,compression=1,
                        fromdate=datetime.datetime(2018,9,1))   
    
    day_bar= cerebro.resampledata(data3, timeframe=bt.TimeFrame.Days,
                        compression=1,name='day_bar')


  • The code is not quite stable as sometimes it would return an error like below, sometimes it would run just fine.

    ***** DATA NOTIF: DELAYED
    ***** DATA NOTIF: DELAYED
    ***** DATA NOTIF: DELAYED
    ***** DATA NOTIF: DELAYED
    ***** DATA NOTIF: UNKNOWN -420
    Traceback (most recent call last):
    .......
    return self.data.datetime.datetime(0)
    File ".../backtrader/linebuffer.py", line 387, in datetime
    return num2date(self.array[self.idx + ago],
    IndexError: array index out of range