Profile Picture

TWS profit target order not resubmitted after disconnect

Posted By alpha23 5 Years Ago

TWS profit target order not resubmitted after disconnect

Message
Posted Monday February 13 2012
I received the following error in RE (build 36):

Error submitting ProfitTarget order: Disconnected: Error! id=-1 errorCode=1100Connectivity between IB and TWS has been lost.

However, the profit target order was not resubmitted when connectivity was restored. See TWS log below.

Please advise.

Thanks, Duane


2012-02-12 21:59:48.0024   n/a   -1   n/a   IB error/warning   2103: Market data farm connection is broken:eurofarm
2012-02-12 22:02:48.1383   n/a   -1   n/a   IB error/warning   2105: HMDS data farm connection is broken:ushmds2a
2012-02-12 22:02:55.5408   n/a   -1   n/a   IB error/warning   2106: HMDS data farm connection is OK:ushmds2a
2012-02-12 22:13:41.2534   n/a   -1   n/a   IB error/warning   2104: Market data farm connection is OK:eurofarm
2012-02-12 22:17:14.4999   n/a   -1   n/a   IB error/warning   1100: Connectivity between IB and TWS has been lost.
2012-02-12 22:17:22.7726   n/a   -1   n/a   IB error/warning   1100: Connectivity between IB and TWS has been lost.
2012-02-12 22:17:31.2900   n/a   -1   n/a   IB error/warning   1100: Connectivity between IB and TWS has been lost.
2012-02-12 22:17:40.3407   n/a   -1   n/a   IB error/warning   1100: Connectivity between IB and TWS has been lost.
2012-02-12 22:17:51.5154   n/a   -1   n/a   IB error/warning   1100: Connectivity between IB and TWS has been lost.
2012-02-12 22:18:02.4835   n/a   -1   n/a   IB error/warning   1102: Connectivity between IB and TWS has been restored - data maintained.
2012-02-12 22:18:02.4835   n/a   n/a   n/a   Reconnected   Sending service event to notify of reconnection and to ask for SyncAccountState to be called
2012-02-12 22:18:02.4865   n/a   n/a   n/a   Connect   SyncAccountState() called
2012-02-12 22:18:02.4865   n/a   n/a   n/a   RequestExecutions   Requesting buy executions, requestID = 2
2012-02-12 22:18:02.4865   n/a   n/a   n/a   RequestExecutions   Requesting sell executions, requestID = 3
2012-02-12 22:18:02.5041   n/a   n/a   n/a   OpenOrderEnd   
2012-02-12 22:18:02.5041   n/a   n/a   n/a   ExecutionDataEnd   Request ID: 2
2012-02-12 22:18:02.5041   n/a   n/a   n/a   ExecutionDataEnd   Request ID: 3
2012-02-12 22:18:02.5041   n/a   n/a   n/a   CurrentTime   Account time updated: 2/12/2012 10:18:00 PM Current time: 2/12/2012 10:18:02 PM Diff: -00:00:02.5050776
2012-02-12 22:18:02.5041   n/a   n/a   n/a   CurrentTime   Current time update recieved, ending connect sync process
2012-02-12 22:18:02.5041   n/a   n/a   n/a   Connect   SyncAccountState ended
2012-02-12 22:27:05.4006   n/a   -1   n/a   IB error/warning   2103: Market data farm connection is broken:usfarm
2012-02-12 22:27:05.8363   n/a   -1   n/a   IB error/warning   2103: Market data farm connection is broken:usfuture
2012-02-12 22:27:10.7538   n/a   -1   n/a   IB error/warning   2104: Market data farm connection is OK:usfuture
2012-02-12 22:27:16.0643   n/a   -1   n/a   IB error/warning   2104: Market data farm connection is OK:usfarm
2012-02-12 22:29:17.3155   n/a   -1   n/a   IB error/warning   2104: Market data farm connection is OK:usfarm
Posted Tuesday February 14 2012
Hi Duane,

RightEdge doesn't have any logic to resubmit profit target/stop loss orders if there is an error submitting them. It doesn't know what the error message it gets means, and in most cases there is probably something wrong with the order and resubmitting it would result in the same error.

If you want to write code to check for this, look at the Orders for a position and see if any of them have a TradeType of ProfitTarget. If not, you can have it resend the profit target by "cancelling" it by calling pos.SetProfitTarget(0, TargetPriceType.None), then calling SetProfitTarget with the value and type you want.

Thanks,
Daniel
Posted Tuesday February 14 2012
Daniel,

   For this specific case, the error was caused only by the fact that TWS connectivity was lost and not in the actual order. Can the RE code be revised to handle lost connectivity with TWS because it is not uncommon in the evening hours and I believe this may affect all order types?

If no, is OrderCancelled called, or is there another method that is called, upon an “Error Submitting XX Order” event?

Thanks, Duane
Posted Friday February 17 2012
For the next build, I've added a SpecialOrderFailed event to PositionManager. It will be raised when there is an error submitting a profit target, stop loss, or trailing stop order. In the handler for the event you can set a flag to resend the profit target once broker connectivity is resumed. You can use the SystemData.ConnectionStateChanged event to listen for this, and check the SystemData.BrokerConnected property to see if the broker is connected. To resubmit a profit target that failed, use the following code:

double profitTarget = position.ProfitTarget;
TargetPriceType type = position.ProfitTargetType;
         
position.SetProfitTarget(0, TargetPriceType.None);
position.SetProfitTarget(profitTarget, type);

Thanks,
Daniel
Posted Monday February 20 2012
Daniel,

Thanks for adding. The functionality will be very helpful.

Duane


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems