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

The latest version, this function (getorders() ) is incorrect
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=16&t=56973
Page 1 of 1

Author:  grosskt [ Tue 19 Mar, 2019, 07:09 ]
Post subject:  The latest version, this function (getorders() ) is incorrect

package COM.Mystrategies;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import java.text.SimpleDateFormat;


public class GetOrdersTest implements IStrategy {
       @Configurable("Instrument")
    public Instrument actinstru = Instrument.USDJPY;
        @Configurable("Amount")
    public double OrderAmount = 0.061;
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
     private final SimpleDateFormat gmtSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    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();
         Set<Instrument> instruments = new HashSet<Instrument>();

        instruments.add(actinstru);
       
        context.setSubscribedInstruments(instruments, true);
    }

    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 {
       
          if (!instrument.equals(this.actinstru)) {
            return;

        }
           if (period.equals(Period.FIVE_MINS))
           {
               submitTwoOrder();
                List<IOrder>  tempOrders=this.engine.getOrders();
                if(tempOrders.size()>1)
                {
                    if(tempOrders.get(0)!=null)
                     DeloneOrder(tempOrders.get(0));
                }
                 List<IOrder>  afterDelOrders=this.engine.getOrders();
                 int norderNums=afterDelOrders.size();
                for(int i=0;i<norderNums;i++)
                {
                     print(String.format("after del one order --cur ordr label=%s,cur order instru=%s --cur order fill time =%s",afterDelOrders.get(i).getLabel(),afterDelOrders.get(i).getInstrument(),gmtSdf.format(afterDelOrders.get(i).getFillTime())));
                }
           }
    }
    public int submitTwoOrder() throws JFException
    {
       List<IOrder>  curOrders=this.engine.getOrders();
       print(String.format("before submit --cur ordr nums=%d",curOrders.size()));
      if(curOrders.size()<1)
      {
         engine.submitOrder("MyMaketBuyOrder_1", actinstru, OrderCommand.BUY, OrderAmount );
         engine.submitOrder("MyMaketBuyOrder_2", actinstru, OrderCommand.BUY, OrderAmount );
         
      }
      curOrders=this.engine.getOrders();
       print(String.format("after submit --cur ordr nums=%d",curOrders.size()));
      int nRetNums=curOrders.size();
      return nRetNums;
    }
    public boolean DeloneOrder(IOrder specOrder) throws JFException
    {
        boolean bRet=true;
        print(String.format("cur order state--=%s",specOrder.getState()));
        if(specOrder.getState()== IOrder.State.FILLED)
        {
            specOrder.close();
            specOrder.waitForUpdate(1000);
        }
        List<IOrder>  curOrders=this.engine.getOrders();
        print(String.format("after del order --cur ordr nums=%d",curOrders.size()));
        return bRet;
       
    }
    private void print(Object o)
    {
        console.getOut().println(o);
    }
}



console print message :
Image

Attachments:
getordernums--error.png [77.6 KiB]
Downloaded 310 times

Author:  API Support [ Tue 19 Mar, 2019, 17:49 ]
Post subject:  Re: The latest version, this function (getorders() ) is incorrect

We were unable to reproduce this issue.
Could you provide more info for reproducing? Especially about orders in console log. When and under what condition they were opened? Did you do it manually or by strategy?

specOrder.waitForUpdate(1000);

It doesn't give you guarantee what after timeout this order will be closed. Closing order may take more than 1000 ms.
Instead, it is recommended to use
specOrder.waitForUpdate(IOrder.State.CLOSED);


Then you can be sure that order will be in closed state after waitForUpdate() method.

Author:  grosskt [ Fri 29 Mar, 2019, 09:02 ]
Post subject:  Re: The latest version, this function (getorders() ) is incorrect

The steps are as follows:
1)
Running strategy program
2)On the platform, after many times of manual work, opening a position, after closing a position,
This bug will appear!!!!
See the print log :
--(note : The currency pair running in the program is USD/JPY. On the platform, if the manually operated currency pair is not USD/JPY, such as: open, EUR/USD or GBP/USD ..., this kind of BUG will appear)

Image

Attachments:
orderbug.png [87.11 KiB]
Downloaded 320 times

Author:  SMARTFX [ Wed 03 Apr, 2019, 21:21 ]
Post subject:  Re: The latest version, this function (getorders() ) is incorrect

Hi Dukascopy support,

I confirm, I am encountering exactly the same issue.

To reproduce the issue, create a dummy strategy with following implementation of onMessage method.
1) Start the strategy, then
2) start selling or buying eur/usd manually from JForex platform
3) observe the console, you will see that for each new order filled there are two entries with the same ExtID. One of the entry is broken IOrder object. The broken object has null fields.

   @Override
   public void onMessage(IMessage message) throws JFException {

      for (IOrder order : engine.getOrders()) {
         System.out.println(order);
      }

   }


Please fix ASAP.

Best regards,
Greg

Author:  API Support [ Thu 04 Apr, 2019, 14:48 ]
Post subject:  Re: The latest version, this function (getorders() ) is incorrect

Fix will be available in next platform release.

Author:  mtnfx [ Fri 05 Apr, 2019, 21:56 ]
Post subject:  Re: The latest version, this function (getorders() ) is incorrect

And ... it would be nice to release updated JForext Client SDK. The latest one was released almost 5 month ago ...

  Page 1 of 1