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?



  • 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.



  • 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.



  • 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.



  • 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.


  • administrators

    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.