If you run your strategy with IClient, consider adding a calendar filter in the following way:
//parse date
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date dateFrom = dateFormat.parse("05/26/2011");
//add calendar filter
CalendarFilter calendarFilter = new CalendarFilter();
calendarFilter.setFrom(dateFrom);
client.addNewsFilter(calendarFilter);
Consider a strategy which just prints calendar events:
package jforex.news;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import com.dukascopy.api.*;
public class CalendarStrategyNoTrades implements IStrategy {
private IConsole console;
@SuppressWarnings("serial")
private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{setTimeZone(TimeZone.getTimeZone("GMT"));}};
private int count;
public void onStart(IContext context) throws JFException {
this.console = context.getConsole();
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
if (message.getType().equals(IMessage.Type.CALENDAR)) {
print("CALENDAR MESSAGE: " + count++ + " " + ((ICalendarMessage) message).getAction() + " "
+ sdf.format(((ICalendarMessage) message).getEventDate()) + " " + ((ICalendarMessage) message).getCountry());
}
}
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException { }
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { }
private void print(Object o){
console.getErr().println(o);
}
}
Note that for historical calendar data you can filter events only over a particular day and with a maximum of 200 events.