Order rejected error handling from notify_order
orenshkol last edited by
When live trading on IB I wish to handle orders rejected by the type of error code received from IB, the problem is that the error code is received in notify_store, when I only want to address errors for rejected orders when I encounter them them in notify_order (notify_store receives many other messages that I don't wish to address).
The only way I see of doing this is by logging notify_store messages as they come in, then getting the last message received for the order id when I get order.Rejected for it in notify_order.
Is there an easier way of doing this? Is there a way of getting the error code from notify_order that I missed?
vladisld last edited by
Unfortunately in current backtrader IBBroker implementation only the following order statuses (coming from IB) are recognized :
SUBMITTED, FILLED, CANCELLED, INACTIVE, PENDINGSUBMIT, PENDINGCANCEL, PRESUBMITTED
See the following code (in IBBroker.py) if you'd like to change/add that:
def push_orderstatus(self, msg): # Cancelled and Submitted with Filled = 0 can be pushed immediately try: order = self.orderbyid[msg.orderId] except KeyError: return # not found, it was not an order if msg.status == self.SUBMITTED and msg.filled == 0: ... elif msg.status == self.CANCELLED: ... elif msg.status == self.PENDINGCANCEL: ... elif msg.status == self.INACTIVE: ... elif msg.status in [self.SUBMITTED, self.FILLED]: ... elif msg.status in [self.PENDINGSUBMIT, self.PRESUBMITTED]: ... else: # Unknown status ... pass