Dukascopy
 
 
Wiki JStore Search Login

IllegalArgumentException: Desired from time is earlier than tick history start time
 Post subject: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Mon 24 Dec, 2012, 16:34 

User rating: 1
Joined: Tue 20 Mar, 2012, 09:03
Posts: 41
With the following sample:

package de.invesdwin.forextrading.sample.instruments;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.LoadingProgressListener;
import com.dukascopy.api.Period;
import com.dukascopy.api.system.ISystemListener;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.TesterFactory;

/**
 * This small program demonstrates how to initialize Dukascopy tester and start a strategy
 */
//CHECKSTYLE:OFF
//@NotThreadSafe
public final class AllInstrumentsTest {
    //CHANGE THIS IN THE SAMPLE BEFORE RUNNING
    private static final String JNLP_URL = de.invesdwin.forextrading.ForexProperties.JFOREX_JNLP_URL.toString();
    private static final String JNLP_USERNAME = de.invesdwin.forextrading.ForexProperties.JFOREX_JNLP_USERNAME;
    private static final String JNLP_PASSWORD = de.invesdwin.forextrading.ForexProperties.JFOREX_JNLP_PASSWORD;

    private AllInstrumentsTest() {}

    public static void main(final String[] args) throws Exception {
        //get the instance of the IClient interface
        final ITesterClient client = TesterFactory.getDefaultInstance();
        //set the listener that will receive system events
        client.setSystemListener(new ISystemListener() {
            @Override
            public void onStart(final long processId) {
                System.out.println("Strategy started: " + processId);
            }

            @Override
            public void onStop(final long processId) {
                System.out.println("Strategy stopped: " + processId);
                final File reportFile = new File("C:\\report.html");
                try {
                    client.createReport(processId, reportFile);
                } catch (final Exception e) {
                    e.printStackTrace();
                }
                if (client.getStartedStrategies().size() == 0) {
                    System.exit(0);
                }
            }

            @Override
            public void onConnect() {
                System.out.println("Connected");
            }

            @Override
            public void onDisconnect() {
                //tester doesn't disconnect
            }
        });

        System.out.println("Connecting...");
        //connect to the server using jnlp, user name and password
        //connection is needed for data downloading
        client.connect(JNLP_URL, JNLP_USERNAME, JNLP_PASSWORD);

        //wait for it to connect
        int i = 10; //wait max ten seconds
        while (i > 0 && !client.isConnected()) {
            Thread.sleep(1000);
            i--;
        }
        if (!client.isConnected()) {
            System.err.println("Failed to connect Dukascopy servers");
            System.exit(1);
        }

        //set instruments that will be used in testing
        final Set<Instrument> instruments = new HashSet<Instrument>();
        //        instruments.add(Instrument.EURUSD);
        for (final Instrument instr : Instrument.values()) {
            instruments.add(instr);
            //            if (instruments.size() >= 10) {
            //                break;
            //            }
        }
        System.out.println("Subscribing instruments...");
        client.setSubscribedInstruments(instruments);
        //setting initial deposit
        client.setInitialDeposit(Instrument.EURUSD.getSecondaryCurrency(), 50000);
        //load data
        System.out.println("Downloading data");
        final List<Future<?>> futures = new ArrayList<Future<?>>();
        futures.add(client.downloadData(null));
        //wait for downloading to complete
        for (final Future<?> future : futures) {
            future.get();
        }
        //start the strategy
        System.out.println("Starting strategy");
        client.startStrategy(new IStrategy() {

            @Override
            public void onTick(final Instrument instrument, final ITick tick) throws JFException {
                System.out.println(tick.getTime());
            }

            @Override
            public void onStop() throws JFException {}

            @Override
            public void onStart(final IContext context) throws JFException {}

            @Override
            public void onMessage(final IMessage message) throws JFException {}

            @Override
            public void onBar(final Instrument instrument, final Period period, final IBar askBar, final IBar bidBar)
                    throws JFException {}

            @Override
            public void onAccount(final IAccount account) throws JFException {}
        }, new LoadingProgressListener() {
            @Override
            public void dataLoaded(final long startTime, final long endTime, final long currentTime,
                    final String information) {
                System.out.println(information);
            }

            @Override
            public void loadingFinished(final boolean allDataLoaded, final long startTime, final long endTime,
                    final long currentTime) {}

            @Override
            public boolean stopJob() {
                return false;
            }
        });
        //now it's running
    }
}


You can reproduce the following exception:
Connecting...
Connected
Subscribing instruments...
Downloading data
Starting strategy
Strategy started: 1
Getting prices before start time
2012-12-24 16:31:09,509 [ |StrategyRunner Thre] ERROR de.invesdwin.ERROR.process                                   - processing #00000001
de.invesdwin.common.log.error.LoggedRuntimeException: #00000001 java.lang.IllegalArgumentException: Desired from time is earlier than tick history start time '2012-12-21 00:00:00:000' > '292278994-08-17 07:12:55:807
        ... 6 omitted, see following cause or error.log
Caused by - java.lang.IllegalArgumentException: Desired from time is earlier than tick history start time '2012-12-21 00:00:00:000' > '292278994-08-17 07:12:55:807
        at com.dukascopy.charts.data.datacache.customperiod.tick.LoadCandlesFromTicksAction.<init>(LoadCandlesFromTicksAction.java:89)
        at com.dukascopy.charts.data.datacache.customperiod.tick.LoadCandlesFromTicksAction.<init>(LoadCandlesFromTicksAction.java:107)
        at com.dukascopy.charts.data.datacache.LoadCustomPeriodNumberOfCandlesAction.loadCandlesFromTicks(LoadCustomPeriodNumberOfCandlesAction.java:123)
        at com.dukascopy.charts.data.datacache.LoadCustomPeriodNumberOfCandlesAction.run(LoadCustomPeriodNumberOfCandlesAction.java:110)
        at com.dukascopy.charts.data.datacache.LoadNumberOfCandlesAction.run(LoadNumberOfCandlesAction.java:177)
        at com.dukascopy.charts.data.datacache.FeedDataProvider.loadCandlesDataBeforeSynched(FeedDataProvider.java:679)
        at com.dukascopy.dds2.greed.agent.strategy.tester.AbstractStrategyRunner.getFirstTicks(AbstractStrategyRunner.java:215)
        at com.dukascopy.dds2.greed.agent.strategy.tester.AbstractStrategyRunner.getFirstTicks(AbstractStrategyRunner.java:202)
        at com.dukascopy.dds2.greed.agent.strategy.tester.StrategyRunner.run(StrategyRunner.java:250)
        at java.lang.Thread.run(Thread.java:722)


What I am trying to do is, just run a strategy on all available instruments. Though this seems to fail because some instruments seem to cause this IllegalArgumentException after loading the data. The exception should either not occur, or atleast tell which instrument caused this problem, so I can filter it.


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Mon 14 Jan, 2013, 13:40 
User avatar

User rating: 0
Joined: Tue 28 Aug, 2012, 12:34
Posts: 10
Location: Spain, Barcelona
Hi guys,
I get the same error message.

Exception in thread "StrategyRunner Thread" java.lang.IllegalArgumentException:
Desired from time is earlier than tick history start time '2012-01-12 00:00:00:000' > '2013-01-14 12:34:25:000

Please, How can I set the history start time?

Code to download data is the following ...

final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
      dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
      Date dateFrom = dateFormat.parse("12/01/2012 00:00:00");
      Date dateTo = dateFormat.parse("14/01/2012 00:00:00");
      client.setDataInterval(DataLoadingMethod.ALL_TICKS, dateFrom.getTime(),dateTo.getTime());
      File fCache = new File("c:\\jforexcache");
      client.setCacheDirectory(fCache);

       Future<?> future = client.downloadData(null);
      // wait for downloading to complete
       future.get()

Thanks!


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Tue 15 Jan, 2013, 07:15 

User rating: 0
Joined: Wed 18 May, 2011, 23:26
Posts: 40
Location: Switzerland,
Try removing jForex-2.12.3.jar from your path/build script/libraries


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Tue 15 Jan, 2013, 14:13 

User rating: 1
Joined: Tue 20 Mar, 2012, 09:03
Posts: 41
I don't have that jar in my classpath. Neither anywhere else.


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Tue 15 Jan, 2013, 14:17 

User rating: 1
Joined: Tue 20 Mar, 2012, 09:03
Posts: 41
@jgravi: your problem can be fixed by invoking a download before setting the timeframe and after again in your code:
final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
      Future<?> future = client.downloadData(null);
      // wait for downloading to complete
       future.get()

      dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
      Date dateFrom = dateFormat.parse("12/01/2012 00:00:00");
      Date dateTo = dateFormat.parse("14/01/2012 00:00:00");
      client.setDataInterval(DataLoadingMethod.ALL_TICKS, dateFrom.getTime(),dateTo.getTime());
      File fCache = new File("c:\\jforexcache");
      client.setCacheDirectory(fCache);
 
       Future<?> future = client.downloadData(null);
      // wait for downloading to complete
       future.get()


I had this problem too and thought it was caused because the most recent data is expected by jforex, but is not being downloaded when specifiying a custom time range. Thus downloading the most recent data before changing to a custom time period fixed this for me. Though this is just a workaround for your problem, which should maybe aswell be fixed inside JForex by the team.

Anyway, the above problem I posted is seemingly unrelated to your problem and should thus NOT be considered as fixed by this workaround...


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Tue 15 Jan, 2013, 16:22 
User avatar

User rating: 0
Joined: Tue 28 Aug, 2012, 12:34
Posts: 10
Location: Spain, Barcelona
Hi,

@buyandhold I don't have the jForex-2.12.3.jar

@Edwin I invoked download before setting the interval but I get the same error.
Now I'm testing without any interval and the error is the same.
Can you help me please? I'm locked!

Future<?> future = client.downloadData(null);       
future.get();
Thread.sleep(5000);


Console message:
Exception in thread "StrategyRunner Thread" java.lang.IllegalArgumentException: Desired from time is earlier than tick history start time '2013-01-12 00:00:00:000' > '2013-01-15 15:21:41:000
at com.dukascopy.charts.data.datacache.customperiod.tick.LoadCandlesFromTicksAction.<init>(LoadCandlesFromTicksAction.java:89)

Thanks!


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Tue 15 Jan, 2013, 16:29 

User rating: 1
Joined: Tue 20 Mar, 2012, 09:03
Posts: 41
Then it seems you are afterall affected by the same bug as me. :)

Though for me it only occurs when trying to subscribe to specific instruments. Instruments like EURUSD and GPBUSD work fine with the above workaround.


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Tue 29 Jan, 2013, 09:13 
User avatar

User rating: 0
Joined: Tue 28 Aug, 2012, 12:34
Posts: 10
Location: Spain, Barcelona
Well, it's not a bug.
Code doesn't work because cache folder is empty. Java is not able to download data.
I've tested the same code in other computer (at home) and it works fine.
I'm trying to execute from job site and maybe there is a firewall that avoids java to store cache,
I'm not sure.


 
 Post subject: Re: IllegalArgumentException: Desired from time is earlier than tick history start time Post rating: 0   New post Posted: Fri 15 Feb, 2013, 11:44 

User rating: 1
Joined: Tue 20 Mar, 2012, 09:03
Posts: 41
This does not apply to me, the bug still affects me and is reproducible with the above sample from various computers in various networks...


 

Jump to:  

  © 1998-2024 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