|
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.
What's the problem of my code ? |
Glickman826
|
Post subject: What's the problem of my code ? |
Post rating: 0
|
Posted: Wed 11 Apr, 2012, 23:53
|
|
User rating: 0
Joined: Sat 24 Mar, 2012, 09:54 Posts: 13
|
I want to download the historical data from 2012-04-03 to 2012-04-05, here is the code: package jforex; import java.util.*; import java.io.*; import java.text.*; import com.dukascopy.api.*;
//@RequiresFullAccess public class DownloadtoCSV3 implements IStrategy { @Configurable("Period") public Period period=Period.ONE_HOUR; @Configurable("Instrument") public Instrument instrument=Instrument.EURUSD; @Configurable("OfferSide") public OfferSide offerSide=OfferSide.BID; private DecimalFormat priceFormat; private SimpleDateFormat gmtsdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private String startDateStr="2012-04-03 00:00:00"; private String endDateStr="2012-04-05 00:00:00"; private int days=3; private IEngine engine; private IConsole console; // use private IHistory history; // use private IContext context; private IIndicators indicators; private IUserInterface userInterface; //@Override public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; this.indicators = context.getIndicators(); this.userInterface = context.getUserInterface(); gmtsdf.setTimeZone(TimeZone.getTimeZone("GMT")); priceFormat=new DecimalFormat("0.#####"); long startDate=0; long endDate=0; try{ startDate=gmtsdf.parse(startDateStr).getTime(); endDate=gmtsdf.parse(endDateStr).getTime(); }catch(ParseException el){ //stop strategy console.getErr().println(el); context.stop(); return; } int k=1; long startTime=0; long endTime=0; long startBarTime=history.getBarStart(period, startTime); long endBarTime=history.getBarStart(period, endTime); print("started!"); try{ List<IBar> bars=history.getBars(instrument,period,OfferSide.BID,endBarTime,startBarTime); for(IBar bar:bars){ print(gmtsdf.format(bar.getTime())+","+k+","+priceFormat.format(bar.getOpen())+","+priceFormat.format(bar.getHigh())+","+priceFormat.format(bar.getLow())+","+ priceFormat.format(bar.getClose())+","+priceFormat.format(bar.getVolume())+"\r\n"); k=k+1; } }catch(Exception e){ console.getErr().println(e.getMessage()); e.printStackTrace(console.getErr()); context.stop(); } } @Override public void onAccount(IAccount account) throws JFException {} @Override public void onMessage(IMessage message) throws JFException {} @Override public void onStop() throws JFException {} @Override public void onTick(Instrument instrument, ITick tick) throws JFException {} @Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {} private void print(Object o){ console.getOut().println(o); } } There was no problems with compiling, however, when I ran the code, only the string "started!" was printed, and no other historical data was printed. What should I do if I want it to print historical data ?
|
|
|
|
 |
API Support
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 09:53
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Insert the following line after the 59th line: print(String.format("from %s to %s retrieved bar count: %s", gmtsdf.format(endBarTime), gmtsdf.format(startBarTime), bars.size()));
|
|
|
|
 |
Glickman826
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 14:57
|
|
User rating: 0
Joined: Sat 24 Mar, 2012, 09:54 Posts: 13
|
There should be some problems with "startBarTime" and "endBarTime" because the print result is:
13:56:32 from 1970-01-01 00:00:00 to 1970-01-01 00:00:00 retrieved bar count: 0
But why the startBarTime was changed to 1970-01-01 00:00:00 ?
|
|
|
|
 |
API Support
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 15:03
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
Glickman826
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 15:49
|
|
User rating: 0
Joined: Sat 24 Mar, 2012, 09:54 Posts: 13
|
Thanks. This problem is solved. By the way, is the time zone of historical data of dukascopy the " GMT+0" ?
|
|
|
|
 |
API Support
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 15:50
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
Glickman826
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 16:05
|
|
User rating: 0
Joined: Sat 24 Mar, 2012, 09:54 Posts: 13
|
In the historical data of dukascopy. Does the non-zero data start from GMT 21:00 Sunday to GMT 20:59 Firday every week ? That's important because I don't need the data of weekends, which should be excluded.
|
|
|
|
 |
API Support
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 16:09
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Market hours - Sunday 9 PM GMT till Friday 9 PM GMT in summer and from Sunday 10 PM GMT till Friday 10 PM GMT in winter.
|
|
|
|
 |
Glickman826
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 16:20
|
|
User rating: 0
Joined: Sat 24 Mar, 2012, 09:54 Posts: 13
|
I can exclude the useless weekends data by using "Filter.WEEKENDS" in the function "history.getBars()", without considering the time is in summer time or winter time, right?
|
|
|
|
 |
API Support
|
Post subject: Re: What's the problem of my code ? |
Post rating: 0
|
Posted: Thu 12 Apr, 2012, 16:54
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|