Oanda Order Execution Time
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, 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?
def expire(self): if self.exectype == Order.Market: return False # will be executed yes or yes if self.valid and self.data.datetime > self.valid: self.status = Order.Expired self.executed.dt = self.data.datetime 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.
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.
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
Your views on these topics will be highly appreciated.