Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

IContext.executeTask() silently does nothing
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=16&t=55855
Page 1 of 1

Author:  mtnfx [ Mon 27 Nov, 2017, 19:21 ]
Post subject:  IContext.executeTask() silently does nothing

Hello, today I came across very strange and very critical problem - IContext.executeTask() silently does nothing while I modify orders. Problem occurs after restart of the strategy.

After lengthy digging and experimenting I've found the cause - instance of IContext provided during first run was cached and reused at later restarts. The reason behind this is - I was trying to make some kind of unit test around my strategy, but it does not matter.

So ... it seems that 'stopped' IContext can still be used (no exception is thrown in any method) and the only symptom of wrong usage is - "IContext.executeTask() silently does nothing". All other methods seem to be working without problems.

I understand this is the rare case, but anyway, to save time of clients, please prevent usage if 'stopped' IContext to avoid hidden bugs.

Author:  API Support [ Tue 05 Dec, 2017, 09:29 ]
Post subject:  Re: IContext.executeTask() silently does nothing

Please provide code that would reproduce the issue.

Author:  mtnfx [ Tue 05 Dec, 2017, 17:42 ]
Post subject:  Re: IContext.executeTask() silently does nothing

API Support wrote:
Please provide code that would reproduce the issue.
Here it is
Note: I expect some exception to be thrown at second invocation of 'g_context.openChart(fd);' and 'g_context.executeTask)'.

Currently
- second 'g_context.openChart()' successfully opens chart,
- second 'g_context.executeTask()' silently does nothing - check strategy output messages.


package jforex;

import java.util.*;
import java.util.concurrent.Callable;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.FeedDescriptor;
import com.dukascopy.api.feed.IFeedDescriptor;

public class StaticContextDemo implements IStrategy {
    private static int g_nRun;
    private static IContext g_context;

    public void onStart(IContext context) throws JFException {
        if( g_context == null )
            g_context = context;

        final IFeedDescriptor fd = new FeedDescriptor();

        fd.setInstrument(Instrument.EURUSD);
        fd.setDataType(DataType.TIME_PERIOD_AGGREGATION);
        fd.setPeriod(Period.THIRTY_MINS);
        fd.setOfferSide(OfferSide.BID);

        ++g_nRun;
        g_context.getConsole().getInfo().println("Starting N: " + g_nRun + ", context: " + System.identityHashCode(g_context));
        g_context.openChart(fd);
        g_context.executeTask(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                g_context.getConsole().getInfo().println("Execute task N: " + g_nRun);
                return null;
            }
        });
    }

    public void onAccount(IAccount account) throws JFException {}
    public void onMessage(IMessage message) throws JFException {}
    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 {}
}

Author:  API Support [ Wed 20 Dec, 2017, 11:29 ]
Post subject:  Re: IContext.executeTask() silently does nothing

This happens because each strategy run has different IContext object. Strategy has to use the correct IContext object that is passed into onStart method.
See the amended strategy version in the attachment.

Attachments:
StaticContextDemo_2.java [1.46 KiB]
Downloaded 168 times

Author:  mtnfx [ Wed 20 Dec, 2017, 15:22 ]
Post subject:  Re: IContext.executeTask() silently does nothing

API Support, i known what i was doing wrong
mtnfx wrote:
... After lengthy digging and experimenting I've found the cause - instance of IContext provided during first run was cached and reused at later restarts ...

My point in this topic is - JForex API does not prevent such wrong usage, it rather silently partially works and because of that it is hard for a user to notice where and why problem occurs.

  Page 1 of 1