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.

Strange problems in getTickBars()
 Post subject: Strange problems in getTickBars() Post rating: 0   New post Posted: Mon 15 Aug, 2011, 23:17 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Hello, I'm busy with the task of sending tick bars into my C++ Dll.
I'm some frustrated with strange behaviour of getTickBars() :
looks like it is not able to take even the well formed time from tick.getTime().

Inside strategy tester I met that it is not able to use ITickBar type
(unknown package com.dukascopy.api.feed) that is also strange.

People, is there a working code somewhere?

My code is here:

        // otherwise we will get "You are not subscribed"
        context.subscribeToTickBarFeed(Instrument.EURUSD, OfferSide.BID, TickBarSize.valueOf(5),
          new ITickBarFeedListener() {
               public void onBar(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, ITickBar bar) {
                   console.getOut().println("On Tick Bar " + " " + instrument + " " + offerSide + " " + tickBarSize + " " + bar);
                }
            }
        );

        try {
          ITick tick = history.getLastTick(Instrument.EURUSD);
          java.util.List<ITickBar> tickBars =
                history.getTickBars(
                      Instrument.EURUSD, OfferSide.BID, TickBarSize.valueOf(5),
                      //tick.getTime(), to - 31 * 24 * 3600 * 1000
                      5000,
                      tick.getTime(),
                      0
                      );
          
          console.getOut().println("---------- getTickBars CALLED.");
          console.getOut().println("---------- GOT TICKBARS, COUNT = " + tickBars.size());
       } catch(Throwable th) {
          console.getOut().println("Error! " + th);

                    // here I get
                // com.dukascopy.api.JFException: Passed Time [2011.08.12 00:00:00 457]
                // has to be in interval [2007.03.30 16:01:15 688; 292269055.12.02 16:47:04 192]
       }



 
 Post subject: Re: Strange problems in getTickBars() Post rating: 0   New post Posted: Thu 18 Aug, 2011, 13:57 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Standalone API uses JForex-API-2.6.43 whilst JForex DEMO client uses JForex-API-2.6.38 this causes some differences between the Standalone API version and Built-in API in JForex DEMO client.
Attachment contains source code for both API versions.
history.getTickBars method is available starting from JForex-API-2.6.43 and, therefore, unavailable in JForex DEMO client.
When you run the strategy from JForex client @RequiresFullAccess annotation needs to be used with call of subscribeToTickBarFeed to allow the application to access the local cache.

It may be useful to turn on java console when running JForex client. Here is how to do it - https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=81&t=39073&p=50123#p50123.


Attachments:
File comment: Standalone API
TickBarStratStandalone.java [2.11 KiB]
Downloaded 319 times
File comment: JForex DEMO client API
TickBarStratJForexClient.java [2.09 KiB]
Downloaded 331 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: Strange problems in getTickBars() Post rating: 0   New post Posted: Thu 18 Aug, 2011, 20:17 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Thank you so much. I will check.


 
 Post subject: Re: Strange problems in getTickBars() Post rating: 0   New post Posted: Thu 18 Aug, 2011, 22:10 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Excuse me, but I am not asking something like "why it does not compile?"
However, the API difference between JForex & standalone is an interesting fact.
My main question is about getTickBars() does not work.

I had found archive with stand alone test strategy
https://www.dukascopy.com/client/jforexl ... ibrary.zip
and added my code into it.

It compiles and runs.
But when I add the code calling getTickBars(),
the code gives me the exception

com.dukascopy.api.JFException: Passed Time [2011.08.12 00:00:00 457]
has to be in interval [2007.03.30 16:01:15 688; 292269055.12.02 16:47:04 192]

You can find modified project in attachment and run it to see this error.
/please add lib files, I had to erase them to place the archive here
as I see, the library JForex-API-2.6.43 is laying there/

My question is "why this exception happens?" because
the year, 2011 is evidently between 2007 and 292269055.


Attachments:
2011-08-19-JForexClientLibrary.rar [11.33 KiB]
Downloaded 321 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: Strange problems in getTickBars() Post rating: 0   New post Posted: Fri 19 Aug, 2011, 08:22 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We were not able to repeat the exception.
Does it repeat for you? Are there any other exceptions in the console before JFException?


 
 Post subject: Re: Strange problems in getTickBars() Post rating: 0   New post Posted: Fri 19 Aug, 2011, 08:47 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Every time the same. Please see the screen shot.
I don't see any other exceptions in the console.


Attachments:
2011-08-19_114633.png [93.4 KiB]
Downloaded 391 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: Strange problems in getTickBars() Post rating: 0   New post Posted: Fri 19 Aug, 2011, 09:03 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Guys, now it runs without problems...

What helped?
I changed instrument EURUSD -> GBPUSD. It had to download the history
from start and it started to work.

Before programming I started JForexDemo app and opened EURUSD
(and this is the instrument that gave problems).

So... it looks like there is either conflict JForexDemo / Standalone
or data cache must be cleaned before running.

PS/ exception's text was wrong, so you may try
to investigate a code


 
 Post subject: Re: Strange problems in getTickBars() Post rating: 0   New post Posted: Fri 19 Aug, 2011, 09:07 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Now I have another question, please :-)

        context.subscribeToTickBarFeed(Instrument.GBPUSD, OfferSide.BID, TickBarSize.valueOf(5), 
          new ITickBarFeedListener() {
               public void onBar(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, ITickBar bar) {
                   console.getOut().println("On Tick Bar " + " " + instrument + " " + offerSide + " " + tickBarSize + " " + bar);
                }
            }
        );
       
        context.subscribeToTickBarFeed(Instrument.EURUSD, OfferSide.BID, TickBarSize.valueOf(5),
          new ITickBarFeedListener() {
               public void onBar(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, ITickBar bar) {
                   console.getOut().println("On Tick Bar " + " " + instrument + " " + offerSide + " " + tickBarSize + " " + bar);
                }
            }
        );
       
       try {
          ITick tick = history.getLastTick(Instrument.EURUSD);
          java.util.List<ITickBar> tickBars =
                history.getTickBars(
                      Instrument.EURUSD, OfferSide.BID, TickBarSize.valueOf(5),
                      //tick.getTime(), to - 31 * 24 * 3600 * 1000
                      5000,
                      tick.getTime(),
                      0
                      );
          
          console.getOut().println("---------- getTickBars CALLED.");
          console.getOut().println("---------- GOT TICKBARS, COUNT = " + tickBars.size());
       } catch(Throwable th) {
          console.getOut().println("Error! " + th);
   
                      //com.dukascopy.api.JFException: Can not load historical Tick Bar data,
                      //please, subscribe to Tick Bar live notification first
       }


Problem disappears if I comment
context.subscribeToTickBarFeed(Instrument.GBPUSD, {...}
line.

Does it mean that I cannot subscribe to more than one instrument?


Attachments:
2011-08-19-JForexClientLibrary.rar [54.45 KiB]
Downloaded 328 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: Strange problems in getTickBars() Post rating: 0   New post Posted: Fri 19 Aug, 2011, 09:51 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Could you, please, give more details on your problem?

In order to use subscribeToTickBarFeed you need to be subscribed to the instrument.
In the standalone client substription is performed in the Main.java class.
To subscribe to GBPUSD default code needs to be modified as follows:
//subscribe to the instruments
Set<Instrument> instruments = new HashSet<Instrument>();
instruments.add(Instrument.EURUSD);
instruments.add(Instrument.GBPUSD);// add this line
See more here:
https://www.dukascopy.com/wiki/index.php ... instrument


 
 Post subject: Re: Strange problems in getTickBars() Post rating: 0   New post Posted: Fri 19 Aug, 2011, 20:10 

User rating: 0
Joined: Mon 15 Aug, 2011, 23:07
Posts: 7
Location: RU
Thank you so much!
Everything is working fine.

PS: I made Common.java with this function ->
I believe, this could make less mistakes

public class Common {
   private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
   static void configureInstruments(IClient client) {
                Set<Instrument> instruments = new HashSet<Instrument>();
                instruments.add(Instrument.EURUSD);
                instruments.add(Instrument.GBPUSD);
                LOGGER.info("Subscribing instruments...");
                client.setSubscribedInstruments(instruments);
   }
}


 

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