How to check for open orders by symbol, or how to cancel all orders for a given symbol/stock?
I have a system where I enter a long position and simultaneously enter a protective stop. I have a separate exit that sometimes occurs. When this occurs, I'd like to be able to cancel the protective stop. I currently use more than one instrument, (currently looking at a basket of 5 stocks), so I'd like to either find a way to determine which orders are still open by symbol or cancel all open orders by symbol.
After looking through the documentation I believe this should be possible but I can't seem to get it to work.
Does anyone have any ideas?
When you get an order notified in
notify_orderyou can assign them to a
dict(probably appending it to a
list) when the order is still
alive(method of the order) and removing it when
As key you can directly use the
dataattribute from the
orderor its, for example
_namewhich is set with the name you give to
To cancel them, just go over the list for an entry an issue
cancelin the strategy.
- See Docs - Strategy