Profile Picture

Buy Limit Orders Cancelled - IB

Posted By alpha23 8 Years Ago
Posted Friday January 08 2010
I'm using IB TWS and RE2 build 14 on a live system. Sell Limit orders placed via profit targets are being placed through the API (ProfitTarget set after a position has been established); however, buy limit orders placed through PositionManager.OpenPosition() are not being sent to TWS (confirmed via reviewing log and IB tech support). It appears the positions are being cancelled within RE with the following error: "Order cancelled while disconnected". The buy limit orders do not contain profit target or stop loss properties.

How do I debug and/or why are the orders being cancelled?

Thanks, Duane

Edited: Friday January 08 2010 by alpha23
Posted Sunday January 10 2010
Was there a disconnect and reconnect involved (either manually or because of an internet connection issue)? You shouldn't get the "order cancelled while disconnected" message unless you are reconnecting.

When you stop a live system, the open positions and pending orders are saved. When you start it again, RightEdge will ask if you want to use the saved positions. If you choose to use some of them, the TWS plugin will try to see if the pending orders are still active. When the plugin connects to TWS, TWS sends it information on all of the outstanding orders. Any orders that were saved from a previous system run but aren't sent to the TWS plugin were presumably cancelled while the system was disconnected, and that's why this message is generated. (It's also possible that the order could have been filled, but in that case TWS should send the fill information when the plugin connects, so the system should correctly process it as filled.)

Posted Sunday January 10 2010
There was no disconnect/reconnect either manually or because of an internet issue. I've ran the system several times with the same results. The error messages are not being generated during the stop and start of a live system. That is, I start the live system with "Run full sim before starting live system" (need to generate the limit orders placed the day before the live start date). Only the buy limit orders are not being sent to TWS.

Interestingly, the sell limit orders set via profit targets after the order was initially placed (placed during the simulation phase) are being sent to TWS. I confirmed that TWS is only receiving the sell limit orders by reviewing the TWS log file, log.Fri in this case, in C:\jts. The buy limit orders place via the OpenPosition method were not in the log file.

I can see the orders being placed in VS by PositionManager and see the orders coming back as cancelled in the OrderCancelled method. You mentioned:

"Any orders that were saved from a previous system run but aren't sent to the TWS plugin were presumably cancelled while the system was disconnected, and that's why this message is generated"

Is there a option that I need to set so that pending orders generated during the simulation phase are still active in the live system? Between the simulation end date and the live start date, is RE viewing this as a disconnect/reconnect? Is there a way to verify that pending orders are saved between the transition of the simulation end date and the live start date? Note, open positions appear to be processed correctly because the sell limit orders are sent TWS.

What information can I verify to isolate the problem or how can I debug the issue since I only have visibility as high as BaseClasses?

Thanks, Duane
Posted Monday January 11 2010
Ah, so it's the "run full sim before starting live system" setting that's causing this. When you use this setting, instead of using the saved positions, it uses the positions from the simulation as the existing positions to send to the broker. That would be why they are being seen as cancelled, because they were never sent to the live broker in the first place.

I'm not sure why the sell limit orders would be handled differently. Are you sure they are being submitted before the system switches to live mode?

I understand that you want the limit orders from the previous day to be sent when you connect to the live broker. The "run full sim" setting doesn't do this, so I think you will have to put some special logic in your system. You will need a way to detect whether the current bar is the last bar before switching to live mode. If so, instead of submitting the orders normally (which would send them to the paper broker), you should add them to a list of orders to be submitted later. Then, once you are connected to the live broker, your system should go through that list of orders and submit them all.


Similar Topics

Reading This Topic

2005-2018 © RightEdge Systems