Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Connect to multiple accounts
 Post subject: Connect to multiple accounts Post rating: 0   New post Posted: Fri 12 Jul, 2013, 00:05 

User rating: 0
Joined: Sat 08 Jun, 2013, 12:05
Posts: 71
Location: FranceFrance
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


 
 Post subject: Re: Connect to multiple accounts Post rating: 0   New post Posted: Fri 12 Jul, 2013, 07:12 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
viewtopic.php?f=65&t=35436


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com