Dukascopy
 
 
Wiki JStore Search Login

DDSJFX-455 Not subscribed to the instrument at autoload
 Post subject: DDSJFX-455 Not subscribed to the instrument at autoload Post rating: 0   New post Posted: Thu 02 Jun, 2011, 11:55 

User rating: -
Hello,

I want to run a strategy with 15 instances.
I created a batch file to auto-load the JForex client, and auto start the strategies.
javaws -J-Djnlp.client.username=USERNAME -J-Djnlp.client.password=PASSWORD -J-Djnlp.strategy.path=SubTest.jfx,audcad;SubTest.jfx,audchf;SubTest.jfx,eurusd;SubTest.jfx,eurcad;SubTest.jfx,eurgbp;
SubTest.jfx,eursek;SubTest.jfx,gbpaud;SubTest.jfx,gbpusd;SubTest.jfx,usdcad;SubTest.jfx,usdsgd;SubTest.jfx,gbpchf;
SubTest.jfx,cadchf;SubTest.jfx,usdjpy;SubTest.jfx,gbpcad;SubTest.jfx,chfjpy https://www.dukascopy.com/client/demo/jclient/jforex.jnlp


In the strategy only the Devizapar (instrument) parameter is configurable/public.

When I run the batch file, the JForex starts to run, and it loads the strategies too.
There is no error, everything seems OK.

But, after the starting, the strategies cannot subscribe on the selected instruments in the onStart method.
I made a for cycle to wait for subscribing, but it didn't help.
In the onTick method the strategy must submit an order, if there is no order in the strategy's instrument.
The submitOrder method make many exceptions on many instruments, for example:
10:36:48 Kivetel elso vetel nyitasakor: com.dukascopy.api.JFException: Not subscribed to the instrument [EUR/GBP]

When I start the strategies manually (without loader), everything goes right.

Here is the sample code which can demonstrate my problem with the loader:
package subtest;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

import javax.swing.SwingConstants;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;
import com.dukascopy.api.drawings.*;

public class SubTest implements IStrategy {
   private IEngine engine = null;
   private int tagCounter = 0;
   private static IConsole console;
   private IAccount account = null;
   private IContext context = null;

   @Configurable("")
   public static Instrument Devizapar = Instrument.EURUSD;
   
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      SubTest.console = context.getConsole();
      this.account = context.getAccount();
      this.context = context;
      
      // regisztraljuk a sajat devizapart
      Set<Instrument> instruments = new HashSet<Instrument>();
      instruments.add(Devizapar);
      context.setSubscribedInstruments(instruments);
      
      // see if Devizapar is already among the instruments
      /*for (Instrument in : context.getSubscribedInstruments()) {
         console.getOut().println("SubscribedInstrument: " + in);
      }*/

      // wait max 5 seconds for the instrument to get subscribed
       int i = 20;
       while (i > 0 && !context.getSubscribedInstruments().contains(Devizapar)) {
        console.getOut().println(Devizapar + " not subscribed yet");
        try {
         Thread.sleep(1000);
        } catch (InterruptedException e) {
         console.getOut().println(e.getMessage());
        }
        i--;
       }

      if(context.getSubscribedInstruments().contains(Devizapar)) {
         console.getOut().println("Felirattuk a devizaparra: " + Devizapar.toString());
      }

      //csvFileToParameters();
      //PrintConsole(parametersToString());
      console.getOut().println("Started.");
   }

   public void onStop() throws JFException {
      /*
       * for (IOrder order : engine.getOrders()) { order.close(); }
       */

      console.getOut().println("Stopped.");
   }

   /*
    * (non-Javadoc)
    *
    * @see com.dukascopy.api.IStrategy#onTick(com.dukascopy.api.Instrument,
    * com.dukascopy.api.ITick)
    */
   public void onTick(Instrument instrument, ITick tick) throws JFException {
        try {
          if(positionsTotal(Devizapar) == 0) {
             engine.submitOrder(getLabel(Devizapar), Devizapar, IEngine.OrderCommand.BUY, 0.001);
          }
        } catch (JFException e) {
            e.printStackTrace();
            console.getOut().println("Kivetel elso vetel nyitasakor: " + e.toString());
        }
   }

   public void onBar(Instrument instrument, Period period, IBar askBar,
         IBar bidBar) {
   }

   // count open positions
   protected int positionsTotal(Instrument instrument) throws JFException {
      int counter = 0;
      for (IOrder order : engine.getOrders(instrument)) {
         if (true/*order.getState() == IOrder.State.FILLED*/) {
            counter++;
         }
      }
      return counter;
   }

   protected String getLabel(Instrument instrument) {
      String label = instrument.name();
      label = label.substring(0, 2) + label.substring(3, 5);
      label = label + (tagCounter++);
      label = label.toLowerCase();
      return label;
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onAccount(IAccount account) throws JFException {
      this.account = account;
   }
}


How could I manage this problem?
Any help is appreciated.
Thanks,
fxmilos


 
 Post subject: Re: DDSJFX-455 Not subscribed to the instrument at autoload Post rating: 0   New post Posted: Thu 15 Dec, 2011, 11:10 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
One option to deal with this is to insert the following code in the beginning of onTick method

       if(context.getSubscribedInstruments().contains(Devizapar)) {
           return;
       }


 

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