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.

How to get news ?
 Post subject: How to get news ? Post rating: 0   New post Posted: Fri 01 Apr, 2011, 03:57 

User rating: -
Hi
I use this code in the login class:
      NewsFilter filter = new NewsFilter();       
      filter.setTimeFrame(NewsFilter.TimeFrame.TODAY);
     
      //set keywords
      Set<String> keywords = filter.getKeywords();
      keywords.add("MARKET TALK");
       
      client.addNewsFilter(filter);
      LOGGER.info("Subscribed : " + filter);
      client.startStrategy(new news());

and the new() class is:
public class news implements IStrategy {
    private IEngine engine;
 
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
    }
 
    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
        if(message.getType() == IMessage.Type.CALENDAR)
       {
           ICalendarMessage c = (ICalendarMessage)message;
           List<ICalendarMessage.Detail> d = c.getDetails();
    
           for(int n = 0; n < d.size(); n++)
           {
               System.out.println("----------->>>>>>>"+d.get(n).getActual()+"----------->>>>>>>"+d.get(n).getDelta()+"----------->>>>>>>"+d.get(n).getPrevious() +"----------->>>>>>>"+d.get(n).getExpected()+"----------->>>>>>>"+d.get(n).getDescription() + "\n")
           }
       }else{
          System.out.println("++++++++++"+message.getType()+"++++++++++");
       }
   
    }


    public void onStop() throws JFException {
        for (IOrder order : engine.getOrders()) {
            engine.getOrder(order.getLabel()).close();
        }
     
    }
 
    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
 
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}



but it can't stop and no any news!!!help...


 
 Post subject: Re: How to get news ? Post rating: 0   New post Posted: Fri 17 Jun, 2011, 11:49 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
For running your strategy from JForex client, see:
https://www.dukascopy.com/wiki/index.php ... de_on_news

For running your strategy from API, consider the following filter:
        NewsFilter newsFilter = new NewsFilter();
        newsFilter.setTimeFrame(NewsFilter.TimeFrame.TODAY);
        newsFilter.getKeywords().add("MARKET TALK");
        client.addNewsFilter(newsFilter);
                       
        CalendarFilter calendarFilter = new CalendarFilter();
        calendarFilter.setTimeFrame(NewsFilter.TimeFrame.TODAY);
        client.addNewsFilter(calendarFilter);
       
        //start the strategy
        LOGGER.info("Starting strategy");
        client.startStrategy(new NewsStrategyNoTrades());
Consider using either the strategy from the above wiki link or the following strategy which just prints the news' messages:
package jforex.news;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

import com.dukascopy.api.*;

public class NewsStrategyNoTrades implements IStrategy {
    private IConsole console;
    @SuppressWarnings("serial")
   private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") {{setTimeZone(TimeZone.getTimeZone("GMT"));}};

    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: " + ((ICalendarMessage) message).getAction() + " " + sdf.format(((ICalendarMessage) message).getEventDate()) + " " + ((ICalendarMessage) message).getCountry());
        } else if (message.getType().equals(IMessage.Type.NEWS)){
            print("NEWS MESSAGE: "  + ((INewsMessage) message).getHeader() + " " + ((INewsMessage) message).getMarketSectors());
        }
    }
    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 news feed works only with live data - you can't receive news in your strategy while working with historical data.


 

Jump to:  

  © 1998-2026 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