Cancel GTC OrderLimit trade with IB

Posted By: ruins

Cancel GTC OrderLimit trade with IB - 11/17/20 02:44

Hi,

I am using a script to enter a GTC OrderLimit order with Interactive Brokers.

OrderLimit = roundto(0.999*priceClose(),PIP);
int GTCFlag = brokerCommand(SET_ORDERTYPE,2); //set order type to good till cancelled.
ThisTrade = enterLong();

I want a GTC order as I dont want the script to wait for the order to be filled before moving onto the next Asset.

If the GTC order in not filled within 1 hour, I want to cancel it, however exitLong() or exitTrade() dont appear to work as for some reason the Quantity associated with the trade is 0 - probably because it is unfilled.

From the API Log I see this:
12:30:00:098 <- 3-43-554732-0-RCL-STK--0---SMART--USD-----SELL-0-LMT-75.51--DAY--xxxxxxxxxx-O-0-Zorro-1-0-0-0-0-0-1-0--0-------0---1-0---0-0--1-1--0------0-----0-----------0---0-0---0--
12:30:00:098 -> 4-2-554732-321-Error validating request.-'bO' : cause - The size value cannot be zero:-

So I cant cancel the LimitOrder within IB from Zorro - however I can cancel it easily from within TWS.

Any ideas on how I can cancel the order from Zorro or achieve the same outcome with other strategies ?

Alternatively, there is a GTD (goodtilldate) option in the TWS API which might be useful however I cant see how that can be exercised from within Zorro.

Thanks.
Posted By: ruins

Re: Cancel GTC OrderLimit trade with IB - 11/17/20 11:12

I did find the following command:

"OrderDuration"
-GTC order duration in seconds.

This would appear to be the same as GTD.

However doesnt appear to cancel the GTC - with IB at least.

Code snippet:
Lots = 100;
OrderDuration = 30;
setf(TradeMode,TR_GTC);
OrderLimit = roundto(0.999*priceClose(),PIP);
ThisTrade = enterLong();
Posted By: jcl

Re: Cancel GTC OrderLimit trade with IB - 11/19/20 08:00

For cancelling the remainder of an unfilled order, select the trade and set TradeLots = TradeLotsTarget-TradeLots, then exit the trade. This should work at least in theory.
© 2024 lite-C Forums