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/

    Ways to repopulate IB trades/orders in strategy after shutdown

    General Code/Help
    2
    2
    168
    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.
    • S
      scottz1 last edited by

      Hey folks, can anyone share thoughts on this? Suppose you have a daily strategy running live in Backtrader with IB, with an active trade and a pending stop order, when your machine shuts off, accidentally or intentionally to save energy for the weekend. Two solutions came to mind, but I'd love to hear others chime in.

      1. When submitting an order or opening a trade, save the object to disk. Read it back in strategy init. Pro: easy to code. Con: could get out of sync with broker, e.g. if broker closes a position or order expires.
      2. In strategy init, call IB Client Portal Web API from to get current state and create a new position and order from it. Pro: accurate broker state. Con: more coding effort and need to make sure all the appropriate fields are populated.
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        • Requirement: Use a specific clientId, ALWAYS the same. You will then only request orders which were issued by your client and not others.

        • Spend your time in extending the broker to retrieve open orders upon connecting to the server.

        • And then match the open orders and current position against your record of open orders and current position.

        You need to take the open position into account, because orders are tied to the specific clientId, but a position is general.

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