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

Trade outside of Regular Trading Hour on IB



  • Hi everyone,

    I am using paper account to trade on IB. My problem is I cannot put DAY order with limit order in after-hours on IB.

    So I was trying to put a limit order in after-hours on IB using the following piece of code:

                    self.log('BUY CREATE, %.2f' % self.data.close[0])
                    self.order = self.buy(
                            size=self.p.size,
                            exectype=bt.Order.Limit,
                            price=round(self.data.close[0] * 1.01, 2),
                            valid=bt.Order.DAY,
                    )
    

    The order wasn't executed even when the limit price is reached. But if I put the limit order with the same value on TWS directly, the order was executed instantly. So by comparing those two orders, I find the order that I manually put on TWS has a DAY time in force while the one created by backtrader don't have a time in force(even though I put valid param as DAY in above code), see the following screenshot.

    Order generated by backtrader:
    Screen Shot 2020-06-22 at 11.35.28 PM.png

    So I wonder if I was doing it in the wrong way or how I could put a limit order with DAY time in force in after-hours.

    Thanks~



  • I'm using the following code to buy/sell outside of regular hours:

    self.buy(data=self.data_feed,
           size=order_size,
           price=lot.buy_price(),
           exectype=Order.Limit ,
           outsideRth=True,
           valid=Order.DAY)
    


  • @vladisld Thank you man! outsideRth=True is what I am looking for!


Log in to reply
 

});