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.

LoadingProgressListener Instrument
 Post subject: LoadingProgressListener Instrument Post rating: 0   Post Posted: Thu 02 Feb, 2012, 02:41 

User rating: 0
Joined: Fri 19 Aug, 2011, 20:29
Posts: 45
Location: Germany,
Is it possible to get the Instrument / Period that LoadingProgressListener is operating on in dataLoaded or loadingFinished?

I'm calling getbars on all subscribed symbols dynamically and in case of an error e.g. allDataLoaded==
false would like to print an error message on which instrument/period the readbars failed.


 
 Post subject: Re: LoadingProgressListener Instrument Post rating: 0   Post Posted: Fri 03 Feb, 2012, 09:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following approach:
package jforex.history;

import com.dukascopy.api.*;

@RequiresFullAccess
public class ReadBarsExample2 implements IStrategy {
   private IContext context;
   private IConsole console;
   private IHistory history;
   private int numberOfBarsLoaded;
   private boolean executed;
   
   public void onStart(IContext context) throws JFException {
      this.context = context;
      this.history = context.getHistory();
      this.console = context.getConsole();
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onStop() throws JFException {
   }

   public void onTick(Instrument instrument, ITick tick) throws JFException {
      if (!executed) {
         console.getOut().println("Calling readBars method");
         history.readBars(Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID,
               history.getBarStart(Period.DAILY, tick.getTime()) - Period.DAILY.getInterval(), // yesterday start
               history.getBarStart(Period.DAILY, tick.getTime()) - Period.TEN_SECS.getInterval(), // yesterday end
               new LoadingDataListener() {
                  public void newTick(Instrument instrument, long time, double ask, double bid, double askVol, double bidVol) {
                     //no ticks expected, because we are loading bars
                  }
                  public void newBar(Instrument instrument, Period period, OfferSide side, long time, double open, double close, double low, double high, double vol) {
                     ++numberOfBarsLoaded;
                  }
               }, new MyLoadingProgressListener(Instrument.EURUSD, Period.TEN_SECS));
         console.getOut().println("Exited readBars method, bars read - " + numberOfBarsLoaded);
         executed = true;
         context.stop();
      }
   }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
   
    private class MyLoadingProgressListener implements LoadingProgressListener{
       
       private final Instrument instrument;
       private final Period period;
       
       public MyLoadingProgressListener (Instrument instrument, Period period){
          this.instrument = instrument;
          this.period = period;
       }

       @Override
       public void dataLoaded(long start, long end, long currentPosition, String information) {
          console.getOut().println(information);
          
       }

       @Override
       public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition) {
         if (allDataLoaded) {
            console.getOut().println(instrument + ", " + period + ", All data loaded succesfully, number of bars loaded: " + numberOfBarsLoaded);
            context.stop();
         } else {
            console.getOut().println(instrument + ", " + period + ", For some reason loading failed or was canceled by the user");
            context.stop();
         }          
       }

       @Override
       public boolean stopJob() {
          // TODO Auto-generated method stub
          return false;
       }
       
    }   
   
}


Attachments:
ReadBarsExample2.java [2.82 KiB]
Downloaded 265 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: LoadingProgressListener Instrument Post rating: 0   Post Posted: Fri 03 Feb, 2012, 12:03 

User rating: 0
Joined: Fri 19 Aug, 2011, 20:29
Posts: 45
Location: Germany,
Had that in mind too. Thanks a lot.


 

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