For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

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?


  • administrators

    When you get an order notified in notify_order you 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 not alive.

    As key you can directly use the data attribute from the order or its, for example _name which is set with the name you give to cerebro.adddata. See

    To cancel them, just go over the list for an entry an issue cancel in the strategy.

Log in to reply