Dukascopy
 
 
Wiki JStore Search Login

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

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

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

Maintaining minimum subscription set for standalone client
 Post subject: Maintaining minimum subscription set for standalone client Post rating: 0   New post Posted: Mon 02 Dec, 2013, 22:20 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
Hi,

I have a standalone "Host" client which runs a variable population of Strategies on an
Amazon Linux server and I want to maintain the minimum amount of network traffic.

Each Strategy has a back link to the IClient "host" and, of course, the IClient has access to its running Strategies through helper interfaces.

Each Strategy trades one instrument, and no other strategy in the population trades that same instrument at any given time. But what I don't know, if when a Strategy stops, how to
properly unsubscribe the Instrument data feed. I can certainly notify the standalone IClient
host in IStrategy.onStop() that's no problem.

My question is: As I stop and start strategies, what is the best way for me to maintain only the Minimum number of subscribed instruments, to minimize network traffic between my server and the Dukascopy servers. I assume IClient maintains the subscribed Instruments list internally as
is the case with the JForex platform.

IClient.setSubscribedInstruments(Set<Instrument> instruments) talks about subscribing
to the given set of instruments, but does it explicitly UNSUBSCRIBE any other instruments?

Again, I'm interested in subscribing only to the minimum required set of instruments
which my Strategies say they need so I don't suffer the network traffic overhead to my server.

AS A DESIGN
So would it be best on any change to my population of Strategies to have the "host"
standalone IClient process execute IClient.setSubscribedInstruments based upon iterating through my
population of running Strategies to assemble the complete minimum set of Instruments
to which I need to be subscribed? I'm most interested in being UNSUBSCRIBED from any
instrument which is not needed.

HyperScalper


 
 Post subject: Re: Maintaining minimum subscription set for standalone client Post rating: 0   New post Posted: Thu 05 Dec, 2013, 13:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
hyperscalper wrote:
IClient.setSubscribedInstruments(Set<Instrument> instruments) talks about subscribing
to the given set of instruments, but does it explicitly UNSUBSCRIBE any other instruments?
Yes it does, unless there is a running strategy which has subscribed to an instrument (by using IContext.setSubscribedInstruments) which is not in the instrument set which you pass in IClient.setSubscribedInstruments. Thus, when running a strategy from the SDK, calling IContext.setSubscribedInstruments effectively "locks" the instrument throughout the strategy execution, such that it can't be removed from the IClient. Which theoretically means that if each of your strategies explicitly subscribes to instruments it is going to work with you could call client.setSubscribedInstruments(Collections.EMPTY_SET); on every strategy stop in order to work with the minimal possible set of instruments at any moment. To see how this works consider the following example:

//the thread every 10 seconds sets a different instrument set
new Thread(new Runnable() {
   Instrument[] instruments = new Instrument[] { Instrument.EURUSD, Instrument.AUDUSD, Instrument.USDJPY, Instrument.USDCAD,
         Instrument.USDCHF, Instrument.USDSGD, Instrument.XAUUSD, };

   private int i = 0;

   @Override
   public void run() {
      while (true) {
         System.err.println("Subscribe: " + instruments[i]);
         client.setSubscribedInstruments(EnumSet.of(instruments[i++]));
         if (i >= instruments.length) {
            i = 0;
         }
         try {
            Thread.sleep(10 * 1000);
         } catch (InterruptedException e) {
            e.printStackTrace();
         }
      }
   }
}).start();

//the strategy simply prints each tick it receives
client.startStrategy(new IStrategy() {

   @Override
   public void onStart(IContext context) throws JFException {
      //EURUSD will not get unsubscribed as long as the strategy will be running
      context.setSubscribedInstruments(EnumSet.of(Instrument.EURUSD));
   }

   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
   }

   @Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {
      System.out.println(instrument + " " + tick);
   }

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

   @Override
   public void onAccount(IAccount account) throws JFException {
   }

   @Override
   public void onStop() throws JFException {
   }
});


Attachments:
ProgramPrintTicksChangeSubscription.java [5.72 KiB]
Downloaded 62 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.
 

Jump to:  

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