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

Oanda Order Execution Time

  • 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 =
        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?

  • Issue #2

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

    def expire(self):
        if self.exectype == Order.Market:
            return False  # will be executed yes or yes
        if self.valid and[0] > self.valid:
            self.status = Order.Expired
            self.executed.dt =[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.

                o = self.oapi.create_order(self.p.account, **okwargs)
            except Exception as e:
       // it should just leave it to that
                return  // but ending the processing of further orders here

  • @backtrader

    Your views on these topics will be highly appreciated.

Log in to reply