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.

Calendar data from multiple periods
 Post subject: Calendar data from multiple periods Post rating: 0   New post Posted: Fri 24 Jun, 2011, 07:10 

User rating: -
How can I get the Calendar data for multiple periods? (for example loop through the last x days/weeks/months of calendar data)


 
 Post subject: Re: Calendar data from multiple periods Post rating: 0   New post Posted: Mon 27 Jun, 2011, 08:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Do you mean java.util.Calendar or historical data over a certain period. In case of the latter, see:
https://www.dukascopy.com/wiki/index.php ... rical_Data


 
 Post subject: Re: Calendar data from multiple periods Post rating: 0   New post Posted: Mon 27 Jun, 2011, 10:19 

User rating: -
nope. None of those.

I mean ICalendarMessage. I like to get them for multiple periods.


 
 Post subject: Re: Calendar data from multiple periods Post rating: 0   New post Posted: Mon 27 Jun, 2011, 12:16 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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.


 
 Post subject: Re: Calendar data from multiple periods Post rating: 0   New post Posted: Mon 27 Jun, 2011, 21:30 

User rating: -
thank you. that code I already saw.

So there is no way to know for certain that you have all the data for a specific day?


 
 Post subject: Re: Calendar data from multiple periods Post rating: 0   New post Posted: Tue 28 Jun, 2011, 08:12 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
trd wrote:
So there is no way to know for certain that you have all the data for a specific day?
Normally the event count per day is well below 100 and since the limit is 200 then it is pretty sure that the filter does return all events for the particular day. Additionally what you can do is to add more specific parameters to the filter, for example to filter events only from USA and Japan:
calendarFilter.getCountries().clear();
calendarFilter.getCountries().add(Country.US);
calendarFilter.getCountries().add(Country.JP);
You can also filter for groups of countries from INewsFilter.Country enum like G7, Europe etc.


 

Jump to:  

cron
  © 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