Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Code/Help
    2
    3
    154
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xingweicmu last edited by

      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~

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        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)
        
        X 1 Reply Last reply Reply Quote 2
        • X
          xingweicmu @vladisld last edited by

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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors