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

IB Live Trading DataFeed on RTH



  • Hello sir, thank you in advance!! I have been struggling with live trading with IB, in my other topic you have provided a great solution on backfilling only regular trading hours' data feeds by set useRTH=Ture.
    However, some new question pops out I feel it's hard to solve. Ideally, my program will run 24/7 on VPS, with live-1min-bar being feed to next(). Even with useRTH=True, next() still getting live data that outside RTH.
    By the nature of bt indicators, say SMA, it is calculated on time window from data[0] to data[-n], which rely on a well-formatted data.
    My target is to have the datafeeds only contains RTH data(3:59 day1 connected to 9:30 day2 for US stocks), in such case the indicators do not mass up by non-trading-hours' data.

    Is there any way I could formate such data from live data feeds? Even with the custom code needed, which approaches you to recommend me to go for, would work better with your package? (1. make the indicator "smarter", so they know non-trading hours' data should be ignored. 2, formate the live data feeds, if it's outside RTH, do not pass to next(). 3. If a non-trading hour bar has been pass to next, use some function to delete that bar in datafeeds, so the data[-1] still inside RTH. 4. Pause the program when the time is outside RTH(might need some good control for such pause) )



  • bt.filters.SessionFilter is the solution.

    data = ibstore.getdata(dataname='AAPL-STK-SMART-USD', timeframe = bt.TimeFrame.Minutes, compression =1,rtbar=True,
                           qcheck=1.0,backfill_start=True,backfill=True,backfill_from =dataHist,latethrough =False,
                           tz='US/Eastern', tzinput ='US/Eastern', useRTH=True, sessionstart=datetime.time(9,30,00),
                            sessionend=datetime.time(16,00,00))
    data.addfilter(bt.filters.SessionFilter)

Log in to reply
 

});