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
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
Comment