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/

    Oanda Order Execution Time

    General Discussion
    1
    3
    650
    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.
    • K
      kausality last edited by kausality

      Issue #1

      I noticed in oanda broker that when the order is executed, the data's current time is used.

      Here is the code which "executes" the order within backtrader:

          data = order.data
          pos = self.getposition(data, clone=False)
          psize, pprice, opened, closed = pos.update(size, price)
      
          comminfo = self.getcommissioninfo(data)
      
          closedvalue = closedcomm = 0.0
          openedvalue = openedcomm = 0.0
          margin = pnl = 0.0
      
          order.execute(data.datetime[0], size, price,  // data current datetime being used
                        closed, closedvalue, closedcomm,
                        opened, openedvalue, openedcomm,
                        margin, pnl,
                        psize, pprice)
      

      Suppose the current data timing of the bar inside backtrader is 23:15 but the order was executed at 23:14 and the store notified to the broker. But in this case, will the execution date still show as 23:15 when during the live trade it was actually executed at the aforementioned time?

      K 1 Reply Last reply Reply Quote 0
      • K
        kausality @kausality last edited by kausality

        Issue #2

        @kausality Aslo related to this issue is the expire() method inside order.py inside backtrader:

        def expire(self):
            if self.exectype == Order.Market:
                return False  # will be executed yes or yes
        
            if self.valid and self.data.datetime[0] > self.valid:
                self.status = Order.Expired
                self.executed.dt = self.data.datetime[0]
                return True
        
            return False
        

        According to this method, the order can only expire if the current data datetime is greater than the max validity time.
        Suppose the data moves in 15 minutes bars inside backtrader. Order expiry was set to 23:13 and the store received the expiry event immediately and sent it to the broker. The order won't expire because the data datetime is still 23:00.

        I am currently trying to make a live store/broker and I am unable to expire order for this same reason. I have to use the follwing code to forcefully expire the order and I am not sure how it affects the order bits:

        order.status = order.Expired  // forceful expiration
        

        I understand that the way backtrader is made, it operates on each iteration of data. But in such a scenario what should be done to expire the order before the next data frame is reached in backtrader? It isn't a big deal while backtesting but it is when doing live trading.

        Issue #3

        I don't want to be pedantic here but I found something in the Oanda store order creator which I don't quite understand now. When an order is rejected for some reason(maybe an HTTP error), the store order creator loop just ends the processing of the order queue. Shouldn't it just mark the order as rejected and continue processing? By ending further processing, no other orders can be created just because one or a few orders were rejected.

        oandastore.py

                try:
                    o = self.oapi.create_order(self.p.account, **okwargs)
                except Exception as e:
                    self.put_notification(e)
                    self.broker._reject(oref) // it should just leave it to that
                    return  // but ending the processing of further orders here
        
        1 Reply Last reply Reply Quote 0
        • K
          kausality last edited by

          @backtrader

          Your views on these topics will be highly appreciated.

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