Please consider the following code to calculate filled orders average price:
public void calculateAveragePrice() throws JFException {
double sumOfPrices = 0;
int orderCount = 0;
for (IOrder order: engine.getOrders()) {
if (order.getState().equals(IOrder.State.FILLED)){
sumOfPrices += order.getOpenPrice();
orderCount ++;
}
}
console.getOut().println("Aerage price for " + orderCount + " orders: " + (sumOfPrices/ orderCount));
}