All my strategies will place bracket order, i.e., an order to get into a position, a limit order to get out of the position and take profit, and a stop order to get out of the position and limit loss. I also allow my strategy to generate signals to exit positions, and when that happens, the limit order and stop order need to be canceled otherwise they will enter an unwanted position.
My solution now is I keep a reference to all the orders I placed, so when I need to cancel any of them, I just use the reference number. This works when my program and IB are both running, but one issue arose during my testing, that is if I connect my program to IB when there are open limit/stop loss orders, I won't be able to reference them, therefore won't be able to cancel them when needed, and later on they will be executed and give me unwanted positions.
My thought is if I can retrieve all the open/active orders from IB, then I will be in full control. From IB API's documentation: https://interactivebrokers.github.io/tws-api/open_orders.html
I see they support this functionality through API, also with backtrader broker I see there is a method called get_orders_open() which gives me exactly what I want, however, I have difficulty finding the corresponding method with ibbroker.
Would anyone please help me solve this issue?
Thanks a lot.