08:50:49 at com.dukascopy.api.impl.h.getBars(Unknown Source)
08:50:49 com.dukascopy.api.JFException: "to" parameter can't be greater than the time of the last formed bar for this instrument
08:50:49 "to" parameter can't be greater than the time of the last formed bar for this instrument
package jforex;
import java.util.*;
import java.io.*;
import java.text.*;
import com.dukascopy.api.*;
@RequiresFullAccess
public class DownloadtoC 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-03-21 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;
try{
startDate=gmtsdf.parse(startDateStr).getTime();
}catch(ParseException el){
//stop strategy
console.getErr().println(el);
context.stop();
return;
}
int k=1;
for(int day=0; day<days; day++){
long startTime=0;
long endTime=0;
startTime=startDate+Period.DAILY.getInterval()*day;
endTime=startTime+Period.DAILY.getInterval()-1; // minus 1 milli to be in the same day
long startBarTime=history.getBarStart(period, startTime);
long endBarTime=history.getBarStart(period, endTime);
try{
List<IBar> bars=history.getBars(instrument,period,OfferSide.BID,startBarTime,endBarTime);
for(IBar bar:bars){
print(k+","+priceFormat.format(bar.getOpen())+","+priceFormat.format(bar.getHigh())+","+priceFormat.format(bar.getLow())+","+
//out.write(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);
}
}