For that particular case you may use this method.
public interface IEngine {
/**
* Returns list of orders in {@link IOrder.State#CREATED}, {@link IOrder.State#OPENED} and {@link IOrder.State#FILLED} state
*
* @return list of orders
* @throws JFException if an error occurred
*/
List<IOrder> getOrders() throws JFException;
/**
* Returns list of orders in {@link IOrder.State#CREATED}, {@link IOrder.State#OPENED} and {@link IOrder.State#FILLED} state for
* specified instrument
*
* @param instrument instrument
* @return list of orders
* @throws JFException if an error occurred
*/
List<IOrder> getOrders(Instrument instrument) throws JFException;
Your code may look like this:
IEngine engine = context.getEngine();
List<IOrder> myOrders = engine.getOrders();
if( myOrders.isEmpty() ) {
DateTimeFormatter YMDHMS = DateTimeFormatter.ofPattern("yyMMdd_HHmmss");
String uniqueLabel = "MyOrder_" + YMDHMS.format(LocalDateTime.now());
engine.submitOrder(uniqueLabel, ...)
}