Make sure you call the method before the test start, see the javadocs, it works just fine in our example program:
package singlejartest;
import java.util.EnumSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.dukascopy.api.*;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.TesterFactory;
public class TesterMainAccountLeverage {
private static final Logger LOGGER = LoggerFactory.getLogger(TesterMainAccountLeverage.class);
public static void main(String[] args) throws Exception {
// get the instance of the IClient interface
final ITesterClient client = TesterFactory.getDefaultInstance();
LOGGER.info("Connecting...");
client.connect("https://www.dukascopy.com/client/demo/jclient/jforex.jnlp", "mzd", "mzd");
int i = 10; // wait max ten seconds for successful connection
while (i-- > 0 && !client.isConnected()) {
Thread.sleep(1000);
}
if (!client.isConnected()) {
LOGGER.error("Failed to connect Dukascopy servers");
System.exit(1);
}
client.setSubscribedInstruments(EnumSet.of(Instrument.EURUSD));
client.setInitialDeposit(Instrument.EURUSD.getSecondaryJFCurrency(), 50000);
client.setLeverage(200);
LOGGER.info("Downloading data");
// wait for downloading to complete
client.downloadData(null).get();
client.startStrategy(new IStrategy(){
@Override
public void onStart(IContext context) throws JFException {
System.out.println("Leverage: " + context.getAccount().getLeverage());
context.stop();
}
public void onTick(Instrument instrument, ITick tick) throws JFException {}
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 {}});
}
}