There are a couple situations when I've seen zipline identify inactive orders as open (i.e. order.status == ORDER_STATUS.OPEN):
-
The order was rejected by IBKR when initially submitted. In this case, a blotter query outside of zipline (using
download_order_statuses()will find the order with Status value of 'Inactive'. -
The order was a GTC stop order that was cancelled outside of zipline. In this case, the blotter Status will be 'Cancelled' (previously 'Pre-Submitted'), but zipline doesn't recognize it. Attempting to force cancel the order from within zipline with
cancel_order()results in an 'order not found' error.
This is a problem for me, because I use get_open_orders() to check for existing orders that haven't filled yet before placing a new order on the same asset. While the blotter sees these orders as inactive, zipline does not.
Is there a way to force zipline to apply/map the correct statuses (ORDER_STATUS.REJECTED or ORDER_STATUS.CANCELLED)?
Deleting the context joblib doesn't work, because the order is marked as open again when zipline replays the transactions in the blotter at the start of each trading session.
