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.

IllegalArgumentException on latest historical data request
 Post subject: IllegalArgumentException on latest historical data request Post rating: 0   New post Posted: Mon 15 Jul, 2013, 08:34 

User rating: 0
Joined: Mon 23 May, 2011, 10:55
Posts: 9
Location: Netherlands,
Hi,

I have a question regarding the request of historical data. I want to have the latest data and do a:

long currTickBarTime = clsHistory.getStartTimeOfCurrentBar(instrument, Period.TWO_SECS);

listTickBars = clsHistory.getTickBars( instrument,
OfferSide.BID,
TickBarSize.TWO,
previous_endtime, currTickBarTime);

but I often get the warning that the To time cannot be greater then the latest known time:

07:16:12 java.lang.IllegalArgumentException: To time could not be greater than latest known time 2013-07-15 07:16:10.0 > 2013-07-15 07:16:09.148

I expected this not to happen since I thought that if I request the current bar this info is in the history. How to prevent this error while still getting the real time up to date data?

Regards


 
 Post subject: Re: IllegalArgumentException on latest historical data request Post rating: 0   New post Posted: Mon 15 Jul, 2013, 15:32 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
Are you trying to return historical 2 Second Bars or are you trying to return historical 2 Tick Bars?
Kindly include a sample strategy incorporating all variable definitions pursuant to providing you with the appropriate assistance


 
 Post subject: Re: IllegalArgumentException on latest historical data request Post rating: 0   New post Posted: Mon 15 Jul, 2013, 17:32 

User rating: 0
Joined: Mon 23 May, 2011, 10:55
Posts: 9
Location: Netherlands,
Hi.

the code I pasted is from the indicator. It needs to get the latest data. I used the 2 seconds to be able to get the latest time. I want all data from the last time checked up till now as in the code above. I added some more lines but since the cause is in the lines I already pasted I dont think it will make it clearer

public IndicatorResult calculate(int startIndex, int endIndex) {
  if ( outputParameterInfos[0].isShowOutput() ||     
   outputParameterInfos[1].isShowOutput() )
  {
    long currTickBarTime = clsHistory.getStartTimeOfCurrentBar(instrument, Period.TWO_SECS);
    Date now = new Date();
    if ( now.getTime() > previous_endtime && previous_endtime < currTickBarTime )
    {
      List<ITickBar> listTickBars;

      try{
     listTickBars = clsHistory.getTickBars( instrument,                       
            OfferSide.BID,
            TickBarSize.TWO,
            previous_endtime, currTickBarTime);
    
     for (ITickBar tickBar: listTickBars)
     {
        
         if ( tickBar.getTime() >= previous_endtime )
         {
        // use the data

        previous_endtime = tickBar.getEndTime();
         }             
        
                                   
     }
   
       } catch (java.lang.IllegalArgumentException e) {print(". " + instrument.toString() + " "  + e);};
    }
  }
}


 
 Post subject: Re: IllegalArgumentException on latest historical data request Post rating: 1   New post Posted: Mon 15 Jul, 2013, 20:13 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
tradelove,

It would be helpful if you acknowledged that you appreciate the difference between a two second Bar and a two tick TickBar and confirm which you are referring to when you say 'data'. I'll take cues from your code and go forward with TickBars.

List<ITickBar> getTickBars(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, long from, long to) [javadoc]
The description there says the two following things:
  • If the requested period includes the bar that is not fully formed yet (in-progress bar), then it is included in result too
  • and about the 'to' parameter - end time of the time interval for which bars should be loaded. This time is included in interval [start; end] of the last loaded bar

Let's suppose the current time is July 15th 2013 13:01:00.
  • The last tick (completing two ticks) came in at 12h:59m:59s.500ms
  • The current 2 Second Bar formed 1 minute ago and it's start time is now your current 'currTickBarTime' (which makes no sense since you have requested a 2 Second Bar and not a TickBar and you have requested the start time of this bar which is 13:00:00 and not the current time nor the start time of the current/last two-tick TickBar in the system).
  • Nonetheless the current time is 13:01:00 (that 2 Second bar will close after 13:01:59 - 2 seconds comprising X amount of ticks).
  • Note also that these 2 second bars continue to form even if there no ticks since they represent OHLC prices with a time bias so if no ticks occur over the 2 seconds the bars are still viable and are flat at the last quoted tick price O = H = L = C.

long getStartTimeOfCurrentBar(Instrument instrument, Period period) [javadoc]
The description there mentions:
  • starting time of the current bar or -1 if no tick was received
  • This is confusing as a 2 second bar can contain 20 ticks so does -1 mean no tick at the start of the bar or that no ticks are being generated for example when the market is closed?
  • if you do a -1 check that might help you to see what is going on also.

Anyway, after some time your indicator calculate() is called where you request TickBars from previous_endtime until currTickBarTime which is 12:59:59.500 (from) - 13:00:00 (to). Your 'to' parameter is greater than the last known tick time which is 12:59:59.500 and has gone beyond as your 'to' reference is Bars which are produced independent of ticks.

Look at your error: 2013-07-15 07:16:10.0 > 2013-07-15 07:16:09.148
  • 2013-07-15 07:16:10.0 is in whole seconds - like what you would get at the beginning of a bar ('to' parameter sent in).
  • 2013-07-15 07:16:09.148 is in milliseconds - which you get from ticks (Last Known Tick Time)

ITick getTick(Instrument instrument, int shift) [javadoc]
If you are tick driven consider using the above getTick(i, s) with a parameter of s=0 to set 'currTickBarTime' which would return 12:59:59.500 instead of the 13:00:00 picked up in the above example.

The Date now thing you have included might be an issue if as your avatar has indicated you are in the Netherlands and have your computer set to local CEST time. All the times within JForex are GMT server times and so your calendar/time functions should ensure GMT use via setting the right Locale information (TimeZone, Calendar, SimpleDateFormat, etc) in order to make meaningful comparisons and ensure integrity. System.currentTimeMillis() saves creating the Date object on every call also.


 
 Post subject: Re: IllegalArgumentException on latest historical data request Post rating: 0   New post Posted: Tue 16 Jul, 2013, 09:13 

User rating: 0
Joined: Mon 23 May, 2011, 10:55
Posts: 9
Location: Netherlands,
thank you for your extensive reply.

you have any idea how I can exclude the in progress bar so that will be included in the next request?


 
 Post subject: Re: IllegalArgumentException on latest historical data request Post rating: 0   New post Posted: Tue 16 Jul, 2013, 12:58 

User rating: 0
Joined: Mon 23 May, 2011, 10:55
Posts: 9
Location: Netherlands,
by the way. I did not use getTick(instrument, 0).getTime() cause that gives give a NullPointerException. (probably starts before the tickstream is initialised?)


 
 Post subject: Re: IllegalArgumentException on latest historical data request Post rating: 0   New post Posted: Tue 16 Jul, 2013, 13:50 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
It certainly can start before your first callback into IStrategy.onTick() as it's in a different thread.
Receiving a NullPointerException isn't a reason to abandon the method if it returns the information you need once the tick stream starts, you'll just have to work out what logic to use. There are many cases where calculate() can be called before the data you might want to use there is ready. Does IContext.getLastTick() return the same?

About the in progress bar I guess you mean the in progress 2 tick tickbar.
As the tickbars are requested using 'from' and 'to' the only way you can discover an in progress 2 tick tickbar is when tickbar.getTime() == tickbar.getEndTime() which means only one tick has been received for the current tickbar, and skip the processing and advancing of 'previous_endtime' accordingly.

ITickBar getTickBar(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, int shift) with shift=0 and then .getTime() gives you the start time of the current forming tickbar which you can also use in your processing.

Hope that helps.


 

Jump to:  

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