I am trying to submit Bracket Orders following this example: IBController 1.3.8 READ ME but I must be doing something wrong as they stay ApiPending (the BUY) and PreSubmitted (the STP), observed in the IBController application window.
The code:
_TRACE("Live Cache: " + NumToStr(av_funds, 1.2));
for (sig=bo.GetFirstSignal(bar); sig; sig=bo.GetNextSignal(bar)) {
if (sig.isLong) {
if (sig.isEntry) {
// Check if already exists
for( i = 0; ( symbol = StrExtract( order_symbols, i ) ) != ""; i++ ) {
if (symbol == sig.Symbol) {
block_buy = True;
break;
}
} if (block_buy) {
continue;
}
// Check if already long
for( i = 0; ( symbol = StrExtract( positions, i ) ) != ""; i++ ) {
if (symbol == sig.Symbol) {
block_buy = True;
break;
}
} if (block_buy) {
continue;
}
//msg = msg + " " + sig.Symbol + ":" + NumToStr(sig.PosSize);
// Bracket order: 2% stop loss
if (ibc.IsConnected()) {
qty = floor(limit / sig.Price);
_TRACE("Transmitting live order: " + sig.Symbol + " BUY: " + NumToStr(qty, 1.0) + " " + NumToStr(sig.Price, 1.2) + " STP: " + NumToStr(sig.Price*0.98, 1.2));
// does not work :(
parent_id = ibc.PlaceOrder( sig.Symbol, "BUY", qty, "MKT", 0, 0, "Day", False ); // todo: limit price
ibc.PlaceOrder( sig.Symbol, "Sell", qty, "STP", sig.Price*0.98, sig.Price*0.98, "GTC", True, 100, "", 0, parent_id );
// works as expected
//ibc.PlaceOrder( sig.Symbol, "Buy", qty, "MKT", 0, 0, "Day", True ); // todo: limit price
}
//_TRACE(msg);
}
if (sig.IsExit()) {
if ( ibc.GetPositionSize( sig.Symbol ) > 0 ) {
ibc.PlaceOrder( sig.Symbol, "Sell", sig.PosSize, "MKT", 0, 0, "Day", False ); // todo: limit price
}
}
}
}
bo.PostProcess();
Output:
Live Cache: 101,805.65
Transmitting live order: AZO BUY: 11 1,620.00 STP: 1,587.60
Tried "GTC" for both orders, did not help.
I might be blind but I really cannot see the substantial difference with the example provided in the guide. Please help.
All additional questions welcome, thanks in advance, etc.