Announcement

Collapse
No announcement yet.

closeAllPositions() does work correctly (Error message: duplicate order id)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • closeAllPositions() does work correctly (Error message: duplicate order id)

    I just found that closeAllPositions() does not work correctly when I mixed manual trading in TWS and API trading with IBBridge.

    The following error is duplicable in my system.

    First I manually place three orders to buy 1 YM, 1 ER2 and 1 NQ contract respectively, which was done between 3:44:31 -- 3:44:37. In IntegratedTrading message window, the order ids were 931 for YM, 932 for ER2 and 933 for NQ.


    At 3:45:08 my script called closeAllPosition() to close the above three contracts. However the order sent by IntegratedTrading to close ER2 position was assigned an order id 931, which has been used before, which resulted an error message "TWS Error: 103; Duplicate order id" at 3:35:09. The rest two orders were assigned id 934 and 935, which were accepted and executed. Thus closeAllPositions() only closed positions in two instruments and failed to close the ER2 long position.

    If I open long position of NQ and YM then try to close them using closeAllPositions(), YM's position will be closed but the order to close NQ will be rejected due to duplicate order id error.

    I suspect somthing is wrong in handling order id in IBBridge implementation. Because it seems it is alway the first instrument sorted in the alphabet order of their symbols in eSignal gets the duplicate order id error, please check the correponding part in the source code to found out what is causing the error.

    I am still struggling with closePosition(symbol). :-(

    - Clearpicks

  • #2
    Message window screenshot
    Attached Files

    Comment


    • #3
      Order window screenshot
      Attached Files

      Comment


      • #4
        I reinstalled esignal/IBBridge/TWS and also tested on my laptop, but I am still not able to get closeAllPositions() working correctly with the same duplicate id error. closePosition(symbol) does not work either.
        Attached Files

        Comment


        • #5
          Originally posted by clearpicks
          I reinstalled esignal/IBBridge/TWS and also tested on my laptop, but I am still not able to get closeAllPositions() working correctly with the same duplicate id error. closePosition(symbol) does not work either.
          Mike,

          I had the same problem last night trading my live account along with the connection going down several times. Not good.

          I know for certain that it worked for the eSignal Paper Broker and thought it worked for IB but is definately not working now and I apologize for misleading you that it was working.

          I'm also seeing errors in the reported P&L in the IB Broker window.
          Glen Demarco
          [email protected]

          Comment


          • #6
            Brent,

            We haven't heard from you on this trading related issue using closePosition() and closeAllPostions()?

            Is someone looking into this on the IB side or should we call their tech support?

            It's very unlikely IMHO an eSignal related issue as the order is making it to IB just fine and being rejected by TWS.

            Also, eSignals implemenation of these functions seem to do what they are intended to do in the eSignal Paper Broker, unlike IB's.


            I've tried coding around it all day and cannot continue trading without those functions working and would appreciate your help.



            Thanks,



            Glen
            Glen Demarco
            [email protected]

            Comment


            • #7
              Glen,

              I think it is more likely an eSignal IBBridge issue instead of IB TWS issue because as far as I know the order id is maintained by IBBridge.

              - Clearpicks

              Originally posted by demarcog
              Brent,

              We haven't heard from you on this trading related issue using closePosition() and closeAllPostions()?

              Is someone looking into this on the IB side or should we call their tech support?

              It's very unlikely IMHO an eSignal related issue as the order is making it to IB just fine and being rejected by TWS.

              Also, eSignals implemenation of these functions seem to do what they are intended to do in the eSignal Paper Broker, unlike IB's.


              I've tried coding around it all day and cannot continue trading without those functions working and would appreciate your help.



              Thanks,



              Glen

              Comment


              • #8
                Actually the problem is more serious than I thought. Whenever I did a trade manually in IB TWS, the next order sent to IBBridge will be rejected due to "TWS Error : 103: Duplicate order id".

                - Clearpicks

                Comment


                • #9
                  Based on what I remember, manual order entry is associated with "client 0". Perhaps your "IBBridge" is using "client 0" as well. I am unfamiliar with IBBRidge, but if it were set to a different client other than the one assigned to to the TWS manual platform, you would not have this issue.

                  Comment


                  • #10
                    Steve,

                    Thanks for the tip. You are right. After changing the client id in IBBridge to 1, the trades manually done in IB TWS are no longer shown in IBBridge's message window and the duplicate order id error is avoided.

                    However there are still quite a few issues:

                    1. closePosition(symbol) does not work.
                    2. cancelOrder(symbol) and cancelAllOrders() can not cancel orders manually set in IB TWS if IBBridge uses client id other than 0.
                    3. If there are positions in multiple instruments, it seems closeAllPositions() does not send out orders to close those positions at the same time. It seems the order sending rate is limited to one or two message per second. In the screenshot attached, I tried to close positions in ES, YM, QQQQ, NQ, ER2, DIA, SPY, QM, YG, USO at the same time using closeAllPositions().
                    However

                    at 11:21:15 orders to close ES was placed
                    at 11:21:16 orders to close NQ was placed
                    at 11:21:17 YM and QQQQ
                    at 11:21:18 DIA and ER2
                    at 11:21:19 QM and SPY
                    at 11:21:20 YG
                    at 11:21:21 USO

                    Is it the IBBridge or IB TWS limiting the number of transactions per second done via API or it is just because I am using IB papertrading account?

                    - Clearpicks



                    Originally posted by stevehare2003
                    Based on what I remember, manual order entry is associated with "client 0". Perhaps your "IBBridge" is using "client 0" as well. I am unfamiliar with IBBRidge, but if it were set to a different client other than the one assigned to to the TWS manual platform, you would not have this issue.
                    Attached Files

                    Comment


                    • #11
                      Mike,

                      Regarding the delay in orders being sent, what do you have specified in the TWS configuration for Configure-API-Fire Open Order On Status Changed?

                      Also, closePosition(symbol) seems to be ignored completely as I receive no message whatsoever using my own code or the gbroker_tester.efs and it's a real problem. I searched the IB customer forum database for an hour and couldn't find anything.
                      Last edited by demarcog; 01-26-2007, 08:57 AM.
                      Glen Demarco
                      [email protected]

                      Comment


                      • #12
                        Glen,

                        "Fire Open Order On Status' Change" is unchecked. What does this option mean? I noticed this option but have not had time to find it out.

                        - Clearpicks



                        Originally posted by demarcog
                        Mike,

                        Regarding the delay in orders being sent, what do you have specified in the TWS configuration for Configure-API-Fire Open Order On Status Changed?

                        Also, closePosition(symbol) seems to be ignored completely as I receive no message whatsoever using my own code or the gbroker_tester.efs and it's a real problem. I searched the IB customer forum database for an hour and couldn't find anything.

                        Comment


                        • #13
                          Originally posted by clearpicks
                          Glen,

                          "Fire Open Order On Status' Change" is unchecked. What does this option mean? I noticed this option but have not had time to find it out.

                          - Clearpicks
                          I'm not the person to ask about the IB interface and options I'm struggling through it myself and the explanation in the help file wasn't much of a ....help. It thought it possibly meant a status change in the bid/offer or last which might explain why the orders were delayed. But the description said a status changes in the order, implying the offsetting order? No idea....

                          Be VERY careful with this cancelAllPositions() fuction for some reason not only did it not cancel my position, but I ended up with larger position sizes then I origionally had!

                          Either the wrong order type (BUY/SELL) went out or it way oversold/overbought. There is also an issue with partials that I have to parse through the messages.


                          I was running a stress test of my system and the IB interface using 10 active symbols which may have been a bit too much, like 9 symbols too much. Haste makes waste, I'm going to crank it back up in about an hour..

                          Would like to hear back from someone at IB ....
                          Last edited by demarcog; 01-26-2007, 09:33 AM.
                          Glen Demarco
                          [email protected]

                          Comment


                          • #14
                            Hi Clearpicks,

                            IB has a pdf document that discusses the functions (and how they work) associated with their API. I do not believe cancelAllOrders(), closePosition() or cancelOrder() are functions or commands that are valid for that platform. If that is the case, any issues or problems you have with the commands are most likely with the software that is communicating with the API.

                            I have a link to the documentation for IB API here. Perhaps that will be helpful in chasing down some of the issues you are having with the interface.

                            Comment


                            • #15
                              The following is what I googled from wiki. It seems the duplicated id error issue can be solved using the technique below.

                              Moreover it would be great to add more flags to cancelOrder(), cancelAllOrders(), closePosition() and closeAllPositions() so that orders put manually in TWS can be included or excluded.

                              - Clearpicks


                              ************************************************** **
                              void nextValidId()
                              Function

                              void nextValidId(long id)

                              Parameters

                              id - The next available order ID received from TWS upon connection. Increment all successive orders by one based on this ID.

                              Notes

                              This function is called after a successful connection to TWS.

                              This method is only called once. You must keep track of this ID yourself and increment it every time you place an order.
                              From Josh Young on IB's discussion board: I use a manually-incremented counter as well with one caveat: when any order status event fires (orderStatus, OpenOrder1, OpenOrder2, OpenOrder3), I check to make sure the order id is not greater than my next order id. If it is, I set my next order id to the order id received in the event + 1. That way, when an order is placed outside of my app (directly in TWS), it doesn't step on my next order id.
                              You need to be careful with this ID. If you placeOrder where the ID is less than the highest ID you've used in the past then you will get a "Duplicate order id" error

                              Comment

                              Working...
                              X