Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Serialization of bracket orders

    General Code/Help
    2
    3
    473
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      z_kvn last edited by z_kvn

      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().

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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.

        Z 1 Reply Last reply Reply Quote 2
        • Z
          z_kvn @backtrader last edited by

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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors