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

Serialization of bracket orders

  • Hi

    Is there any way to serialize open orders from a bracket order (I.e an open stop loss order and an open take profit order ) so that when a new backtrader process is started, the new process is able to pick up the open orders from disk?

    Due to various issues it is highly likely that a live trading backtrader process may be interrupted (ib gateway shutdown, internet issue, blackout etc). It is easy to handle a left over open position but I don't know how to deal with those lurking Stoploss/take profit orders as they don't not show up in notify_orders().

  • administrators

    Not really. Consider this:

    • Your script serialize the orders to disk
    • Your script goes to the toilet (scripts do also have rights and needs)
    • Your script loads the orders from the disk and carries on

    What if:

    • The orders had actually been executed/cancelled during the toilet break?

    You immediately think:

    • Serialization is coupled with fetching the actual orders from the broker to match them to existing orders and if they are not existing they will be discarded

    But now you have to consider that, even if you discard them

    • Now you would have to understand if the orders were executed and that has opened/modified/closed a position
    • Which means you have not only now to fetch the pending orders, you have to also fetch the history of pending/cancelled orders and match them to your current situation

    One could still add a couple of scenarios.

    Understanding your point, that's why the chosen approach is simplistic: assume things start always from scratch, to simplify everything.

    It may not be the best approach for sure ... but it's the one.

  • @backtrader Got you. Thanks for the detailed explanation. The simplistic approach does make sense. Guess I will handle the open orders manually.

Log in to reply