......
// first, count filled position
int count = 0;
List<IOrder> AllPositions = engine.getOrders(instrument);
for (IOrder order: AllPositions) {
if (order.getState().equals(IOrder.State.FILLED)){
count = count + 1;
}
}
// then if open positions > 10, close all position
if ( count >= 10 ){
// in real life after executing order.close(), AllPositions might point to invalid data
// so this code below is not recomended, but hope you got the idea
for (IOrder order: AllPositions) {
if (order.getState().equals(IOrder.State.FILLED)){
order.close();
// should wait some time here
}
}
}
.......