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.

issue with ISystemListener remaining connected
 Post subject: issue with ISystemListener remaining connected Post rating: 0   New post Posted: Wed 14 Dec, 2011, 19:13 

User rating: 0
Joined: Wed 14 Dec, 2011, 19:08
Posts: 7
Location: US
I am using the standalone in Net Beans. A new thread is created which connects the client and sets the listener. I can't seem to disconnect or stop the listener and close the thread. In your sample app, you use System.exit(1), which I do not wish to use. I simply want to disconnect from the desk and stop all listeners.
Thank you


 
 Post subject: Re: issue with ISystemListener remaining connected Post rating: 0   New post Posted: Thu 15 Dec, 2011, 12:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Could you please provide code sample and describe when do you want your thread to stop.


 
 Post subject: Re: issue with ISystemListener remaining connected Post rating: 0   New post Posted: Sun 18 Dec, 2011, 16:35 

User rating: 0
Joined: Wed 14 Dec, 2011, 19:08
Posts: 7
Location: US
below is some skeleton code from 3 classes.
Upon monitoring the threads in debug mode, when I call client.stopStrategy(SprocessId);
the strategy stops. however all the listener threads remain open. I would like all threads which started through the "AccountDesk" class to stop. I have unsuccessfully tried thread.stop(), interrupt, etc.. the call loop exists, however the listener threads remain active.

Here is the theory behind what I am trying to accomplish. Say I have multiple accounts which would be trading the same set of trades coming from a Database. My main application which is always running, should be able to start and stop accounts at any given time.

at this point I am down to a solution which is not acceptable. have my main app call a new JVM from the command line for each individual account, and then use system.exit() in each account.

please help implement my original plan.
Thank you


**************************************************
//main CLASS

new Thread(new AccountDesk().start();


**************************************************
//AccountDesk

public class AccountDesk implements Runnable{
   
    private String jnlpUrl="https://www.dukascopy.com/client/demo/jclient/jforex.jnlp";
    private String userName="ghghh";
    private String password="ghghghg";
   
    private IClient client;
    private Instrument instrument;
    private Long SprocessId;
    private int AccountID=1;
   

   
    public void run() {


       
        try {
           client= ClientFactory.getDefaultInstance();
           SetListener();

               Set<Instrument> instruments = new HashSet<Instrument>();
               instruments.add(Instrument.valueOf("EURUSD"));
               client.setSubscribedInstruments(instruments);

               client.startStrategy(new AccountStrategy(AccountID));
        }

        catch (Exception e) {
        }

               

        try {
            while (Thread.currentThread().isAlive()) {
                Thread.sleep(1000);

         
         //DATABASE DRIVEN FLAG TO QUIT
                if(!AccountRS.getBoolean("ROBOT_ACTIVE")){
                    client.stopStrategy(SprocessId);
                    break;
                }
            }

        }
        catch (InterruptedException e){}
        catch (Exception e) {

        }

    }




    private void SetListener(){

        client.setSystemListener(new ISystemListener() {
           
                private int lightReconnects = 3;

           @Override
           public void onStart(long processId) {
                    SprocessId=processId;
           }

                @Override
      public void onStop(long processId) {
                }

      @Override
      public void onConnect() {
                lightReconnects = 3;
      }

      @Override
      public void onDisconnect() {

                    if (lightReconnects > 0) {
                        client.reconnect();
                        --lightReconnects;
                    }
                    else {
                        try {
                            Thread.sleep(10000);
                        }
                        catch (InterruptedException e) {
                        }
                        try {
                            client.connect(jnlpUrl, userName, password);
                        }
                        catch (Exception e) {
                        }
                    }
      }
   
        });
    }

}


**************************************************
//AccountStrategy

public class AccountStrategy implements IStrategy {
   

    private int AccountID;
    public AccountStrategy(int ID){AccountID=ID;}

    public void onStart(IContext context) throws JFException {
    }
    public void onStop() throws JFException {
    }
    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
    }
    public void onMessage(IMessage message) throws JFException {
    }
    public void onAccount(IAccount account) throws JFException {
    }
   

}


 
 Post subject: Re: issue with ISystemListener remaining connected Post rating: 0   New post Posted: Fri 23 Dec, 2011, 04:12 

User rating: 0
Joined: Wed 14 Dec, 2011, 19:08
Posts: 7
Location: US
It's been a week. and it's driving me crazy. any clues?


 
 Post subject: Re: issue with ISystemListener remaining connected Post rating: 0   New post Posted: Tue 27 Dec, 2011, 12:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
In the current API implementation you can only force disconnect by stopping the process which has connected IClient (hence, you need an application which handles multiple processes). With the next release of Standalone API, one will be able to disconnect by calling IClient.disconnect.


 

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