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/

    Is there way to track open orders with IB broker?

    General Discussion
    3
    5
    1324
    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.
    • A
      albertzgd last edited by albertzgd

      I am testing my code with live paper trading with Interactive Broker. My strategies always create a profit-taking limit order and a stop loss order whenever a position is entered. I ran my code with backtesting broker and everything is fine, however, when I ran it with IB broker, I get the error message of:

      ***** STORE NOTIF: <error id=2184, errorCode=201, errorMsg=Order rejected - reason: Your account has a minimum of 15 orders working on either the buy or sell side for this particular contract. An additional order on the same side for this contract will not be allowed until an existing order has been canceled or has executed. Please call the Trade Desk for further details.>

      I am suspecting this may be due to the profit taking orders and stop loss orders not canceled properly. For debugging purposes, I would like to track the open(pending) orders. With backtesting broker, I can do self.broket.pendings, is there an equivalent method in ib broker?

      Thanks in advance for any information.

      1 Reply Last reply Reply Quote 0
      • A
        albertzgd last edited by albertzgd

        I found the solution by reading backtrader's source code.

        In case anyone is interested, strategy class has a data attribute ._orderspending that contains all the pending orders.

        Edit: This doesn't really work.

        1 Reply Last reply Reply Quote 0
        • A
          albertzgd last edited by

          Besides, the reason why I get a bunch of unexecuted and uncanceled orders is that short is not allowed for equities in the demo system during the time I tested my code(I don't know if this is temporary or in demo system, one just can't short equities).

          So all the short orders are held. Held orders will not show as pending orders.

          1 Reply Last reply Reply Quote 0
          • N
            nooby_mcnoob last edited by nooby_mcnoob

            Here is how I debug live trades:

            1. Use notify_trade and notify_order functions and print out the status as it comes in
            2. Don't use GTC orders unless your strategy cancels orders. I use time-limited orders

            Additionally, when I place an order, I assign the current order to a member: self._order = ... and unset it when notify_trade marks it as closed. Then, I don't do any of the strategy logic unless self._order is None.

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

              I guess the problem is not tracking the actual orders you have sent, but checking previous orders which are in the system. backtrader is not conceived as a manager of your account and won't check for existing open orders.

              As pointed out by @nooby_mcnoob, you can use notify_order to track the orders which you have sent.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }