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.

IContext.executeTask() silently does nothing
 Post subject: IContext.executeTask() silently does nothing Post rating: 0   New post Posted: Mon 27 Nov, 2017, 19:21 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
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.


 
 Post subject: Re: IContext.executeTask() silently does nothing Post rating: 0   New post Posted: Tue 05 Dec, 2017, 09:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide code that would reproduce the issue.


 
 Post subject: Re: IContext.executeTask() silently does nothing Post rating: 0   New post Posted: Tue 05 Dec, 2017, 17:42 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
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 {}
}


 
 Post subject: Re: IContext.executeTask() silently does nothing Post rating: 0   New post Posted: Wed 20 Dec, 2017, 11:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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 156 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: IContext.executeTask() silently does nothing Post rating: 0   New post Posted: Wed 20 Dec, 2017, 15:22 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
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.


 

Jump to:  

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