How could I connect to multiple accounts in the same project, it seems the use of
https://www.dukascopy.com/client/javadoc/com/dukascopy/api/system/ClientFactory.html#getDefaultInstance() prevent that.
public class Multi {
public static void main(String[] args) {
Thread t1 = new Thread(new Client("uuu", "iii"));
Thread t2 = new Thread(new Client( "yyy", "zzz"));
t1.start();
t2.start();
}
}
class Client implements Runnable{
String jnlpUrl = "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
String user;
String pw;
public Client(String user, String pw){
this.user=user;
this.pw=pw;
}
public void run() {
System.out.println("start cl "+Thread.currentThread().getId());
IClient client;
try {
client = ClientFactory.getDefaultInstance();
client.setSystemListener(new ISystemListener() {
public void onStart(long processId) {
System.out.println("myplay started: " + processId);
}
public void onStop(long processId) {
System.out.println("myplay stopped: " + processId);
}
public void onConnect() {
System.out.println("Connected");
}
public void onDisconnect() {
System.out.println("Disconnected");
}
});
client.connect(jnlpUrl, user, pw);
//workaround for LoadNumberOfCandlesAction for JForex-API versions > 2.6.64
Thread.sleep(5000);
client.startStrategy(new IStrategy(){
public void onStart(IContext context) throws JFException {
System.out.println("start s"+Thread.currentThread().getId());
}
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 a) throws JFException {
System.out.println("acc"+Thread.currentThread().getId()+" "+a.getAccountId());
}
public void onStop() throws JFException {
System.out.println("stop s"+Thread.currentThread().getId());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
running the two threads only shows the messages from one of the account
acc s53 630447
acc s56 630447
acc s53 630447
acc s56 630447
acc s53 630447
acc s56 630447
...
it seems the only way will be to run separate maven apps?
not really handy for managing multiple accounts