I am working with a strategy that can only deal with one filled order at a time, for money management purposes. I am trying to program a way to cancel all pending orders when one order fills. I have come up with this:
public void onTick(Instrument instrument, ITick tick) throws JFException {
// Cancelling Pending Orders If An Order Is Filled
for (IOrder allOrders : engine.getOrders()) {
if (allOrders.getState() == IOrder.State.FILLED) {
for (IOrder order : engine.getOrders()) {
if (order.getState() == IOrder.State.OPENED) {
order.close();
}
}
break;
}
}
}
Is there a more efficient way to program this?