These are my 2 methods for connect and disconnect. When i connect to account, disconnect and try to connect to different account platform connects to first account.
How can i connect to another account after i connected to some account? There is no disconnect method in Client.
public void connect() throws JFAuthenticationException, JFVersionException, Exception {
if (this.isConnected()) {
return;
}
this.dcClient = ClientFactory.getDefaultInstance();
System.err.println("Dclogin " + dCLogin + " passwd" + dCPassword);
dcClient.connect(jnlpUrl, dCLogin, dCPassword);
int i = 10; //wait max ten seconds
while (i > 0 && !dcClient.isConnected()) {
Thread.sleep(1000);
i--;
}
if (!dcClient.isConnected()) {
throw new Exception("Can not connect to client. Time expired.");
}
Set<Instrument> setOfInstruments = new HashSet<Instrument>();
setOfInstruments.add(Instrument.EURUSD);
setOfInstruments.add(Instrument.NZDJPY);
dcClient.setSubscribedInstruments(setOfInstruments);
this.emptyStrategy = new EmptyStrategy();
long id = dcClient.startStrategy(this.emptyStrategy);
this.emptyStrategy.setId(id);
}
public void disconnect() throws InterruptedException, Exception {
if (!this.dcClient.getStartedStrategies().isEmpty()) {
//stop all the strategies
}
this.dcClient.stopStrategy(this.emptyStrategy.getId());
int i = 10; //wait max ten seconds
while (i > 0 && !dcClient.isConnected()) {
Thread.sleep(1000);
i--;
}
if (!this.dcClient.getStartedStrategies().isEmpty()) {
throw new Exception("Can not stop strategies. Time expired.");
}
this.dcClient = null;
System.gc();
}