Currently it is not included in the API. Consider the following strategy which prints out the position summary:
package jforex.info;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import com.dukascopy.api.*;
/**
* The strategy prints position summary over an instrument: order count, order amount and weighed price
* The data reflects those shown in "Position Summary" tab
*
*/
public class PositionSummaryOnTick implements IStrategy {
private IEngine engine;
private IConsole console;
private Instrument instrument = Instrument.GBPUSD;
@SuppressWarnings("serial")
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{setTimeZone(TimeZone.getTimeZone("GMT"));}};
private DecimalFormat df = new DecimalFormat("0.00000");
@Override
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
if(instrument != this.instrument)
return;
printPositionSummary(tick.getTime());
}
private void printPositionSummary(long time) throws JFException {
int orderCount = 0;
double totalAmount = 0;
double weightedPrice = 0;
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() != IOrder.State.FILLED)
continue;
orderCount++;
//Negate SHORT orders
double amount = order.getAmount() * (order.isLong() ? 1 : -1);
totalAmount += amount;
weightedPrice += amount * order.getOpenPrice();
}
//normalize weighted price - as if amount sum were 1
weightedPrice /= totalAmount;
print(sdf.format(time) + " Order Count=" + orderCount + " Total Amount="+totalAmount + " Weighted Price=" + df.format(weightedPrice));
}
private void print(Object o){
console.getOut().println(o);
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
public void onMessage(IMessage message) throws JFException {}
public void onAccount(IAccount account) throws JFException {}
public void onStop() throws JFException {}
}