Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

subscribeToFeed() doesn't work correctly in HistoricalTester
 Post subject: subscribeToFeed() doesn't work correctly in HistoricalTester Post rating: 0   New post Posted: Wed 13 May, 2015, 09:13 

User rating: 0
Joined: Wed 12 Jun, 2013, 16:19
Posts: 18
Location: PolandPoland
Hello

When I subscribe the feed with custom period (like a 2 minutes) and check this Strategy in Historical Tester then I never recieve the currently formed bar.
The same strategy work like a harm outside the Historical Tester :).

Expected result: not-empty IBar object

import com.dukascopy.api.*;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;


public class ExampleStrategy implements IStrategy {
   
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    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();
       
        // Test custom feed subscribtion
        Period customPeriod = Period.createCustomPeriod( Unit.Minute, 2 );
        IFeedDescriptor myFeed = new TimePeriodAggregationFeedDescriptor( Instrument.EURUSD, customPeriod, OfferSide.BID );
        context.subscribeToFeed(myFeed, new IFeedListener() {
            @Override
            public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
                // do nothing
            }
        });
       
        // Waiting for the current bar (I use the subscribed feed with custom period)
        while( context.getHistory().getBar(myFeed.getInstrument(), myFeed.getPeriod(), myFeed.getOfferSide(), 0) == null ) {
            int waiting = 1;
        }
       
        // Expected result: not-empty IBar object
        console.getOut().println(context.getHistory().getBar(myFeed.getInstrument(), myFeed.getPeriod(), myFeed.getOfferSide(), 0));
    }

    @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 {
    }
}


Attachments:
ExampleStrategy.java [2.11 KiB]
Downloaded 144 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: subscribeToFeed() doesn't work correctly in HistoricalTester Post rating: 0   New post Posted: Fri 15 May, 2015, 09:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We are investigating this


 
 Post subject: Re: subscribeToFeed() doesn't work correctly in HistoricalTester Post rating: 0   New post Posted: Fri 15 May, 2015, 12:34 

User rating: 0
Joined: Wed 12 Jun, 2013, 16:19
Posts: 18
Location: PolandPoland
API Support wrote:
We are investigating this


Thanks :)


 
 Post subject: Re: subscribeToFeed() doesn't work correctly in HistoricalTester Post rating: 0   New post Posted: Wed 27 May, 2015, 12:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Historical Tester receives historical data in the same thread where it executes strategy, so waiting cycle in IStrategy.onStart() method blocks it.
One should use IFeedListener.onFeedData() callback method to receive loaded data.

import com.dukascopy.api.*;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
 
public class ExampleStrategy implements IStrategy {
   
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    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();
       
        // Test custom feed subscribtion
        Period customPeriod = Period.createCustomPeriod( Unit.Minute, 2 );
        IFeedDescriptor myFeed = new TimePeriodAggregationFeedDescriptor( Instrument.EURUSD, customPeriod, OfferSide.BID );
 
        context.subscribeToFeed(myFeed, new IFeedListener() {
            @Override
            public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
                try {
                    console.getOut().println("finished bar: " + feedData);
                    console.getOut().println("current bar: " + history.getBar(feedDescriptor.getInstrument(), feedDescriptor.getPeriod(), feedDescriptor.getOfferSide(), 0));
                } catch (JFException ex) {
                    console.getErr().println(ex.getMessage());
                }
            }
        });
    }
 
    @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 {
    }
}


 

Jump to:  

  © 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