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.

IEngine.broadcast revisited
 Post subject: IEngine.broadcast revisited Post rating: 1   New post Posted: Mon 16 Dec, 2013, 23:26 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
I think it's a bug that the IEngine.broadcast pacing does
not appear to be on a per-Strategy basis.

Each strategy instance should be able to pace itself with the
mandatory delay of 1000+ msecs since the last broadcast
and function correctly, avoiding the pacing exception.

But, correct me if I'm wrong, it appears this isn't true;
if you run the attached strategy it's just fine. But if you
concurrently run another instance of that strategy
(just copy and rename the .jfx) then we get the
exception constantly.

You'll need the Java Console running to see the exceptions.

com.dukascopy.api.JFException: Broadcast min period exceeded : 365 / 1000
   at com.dukascopy.api.impl.connect.bh.broadcast(Unknown Source)
   at com.fs.strategy.IEngineBroadcastBug$BroadcastExecutableTask.call(IEngineBroadcastBug.java:59)
   at com.fs.strategy.IEngineBroadcastBug$BroadcastExecutableTask.call(IEngineBroadcastBug.java:1)
   at com.dukascopy.api.impl.execution.k.call(Unknown Source)
   at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
   at java.util.concurrent.FutureTask.run(Unknown Source)
   at com.dukascopy.api.impl.execution.g$a.f(Unknown Source)
   at com.dukascopy.api.impl.execution.g$a.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: com.dukascopy.jss.JssException: Broadcast min period exceeded : 365 / 1000
   at com.dukascopy.jss.b.j(Unknown Source)
   ... 9 more
com.dukascopy.api.JFException: Broadcast min period exceeded : 365 / 1000
   at com.dukascopy.api.impl.connect.bh.broadcast(Unknown Source)
   at com.fs.strategy.IEngineBroadcastBug$BroadcastExecutableTask.call(IEngineBroadcastBug.java:59)
   at com.fs.strategy.IEngineBroadcastBug$BroadcastExecutableTask.call(IEngineBroadcastBug.java:1)
   at com.dukascopy.api.impl.execution.k.call(Unknown Source)
   at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
   at java.util.concurrent.FutureTask.run(Unknown Source)
   at com.dukascopy.api.impl.execution.g$a.f(Unknown Source)
   at com.dukascopy.api.impl.execution.g$a.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: com.dukascopy.jss.JssException: Broadcast min period exceeded : 365 / 1000
   at com.dukascopy.jss.b.j(Unknown Source)
   ... 9 more
...............forever


Feel free to hack it any way you want, but I think that
the IEngine.broadcast Mandatory delay should be per-Strategy. Otherwise,
with multiple Strategies using broadcast, there is almost
no way for them to avoid the minimum delay violation
as they are running concurrently.

In my case, I implemented a standalone client Global
pacing solution, but that's just not practical for ordinary
Strategy modules.

Apologies if I'm completely wrong here.....

Thanks for looking into this !!
HyperScalper

//package com.fs.strategy;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;

public class IEngineBroadcastBug implements IStrategy {

   IContext context = null;
   IEngine engine = null;
   IConsole console = null;
   
   volatile private boolean isRunning = true;
   volatile long lastBroadcastTimestamp = 0;
   
   final private long now() {
      return System.currentTimeMillis();
   }
   
   // waits until 1100 msecs has elapsed since
   // the lastBroadcastTimestamp
   final private void mandatoryDelay() {
      long now = now();
      if (lastBroadcastTimestamp==0) { // first time
         lastBroadcastTimestamp = now;
         return; // no delay
      }
      int elapsed = (int)(now - lastBroadcastTimestamp);
      if (elapsed<1100) { // add an extra 100 msecs
         int msecsWait = (1100-elapsed); // remainder to wait
         if (msecsWait<10) msecsWait=10;
         try {
            Thread.sleep(msecsWait);
         }
         catch(Exception e) {
            e.printStackTrace();
         }
      }
   }
   
   // queued using IContext.executeTask(Callable)
   class BroadcastExecutableTask implements Callable<Void> {
      
      public Void call() {
         try {
            mandatoryDelay();
            lastBroadcastTimestamp = now();
            try {
               console.getOut().println("broadcast...");
               engine.broadcast("test","test");
            }
            catch(Exception e) {
               e.printStackTrace();
            }
         }
         catch(Exception e) {
            e.printStackTrace();
         }
         return null;
      }
   }
   
   public class BroadcastLoop implements Runnable {
      public void run() {
         while (isRunning) {
            try {
               Thread.sleep(1000);
               
            }
            catch(Exception e) {
               e.printStackTrace();
            }
            if ( !isRunning) continue; // quit
            BroadcastExecutableTask task = new BroadcastExecutableTask();
            Future<Void> future = null;
            try {
               future = context.executeTask(task);
               future.get(); // wait synchronous
            }
            catch(Exception e) {
               e.printStackTrace();
            }
         } // end while
      }
   }
   
   @Override
   public void onStart(IContext context) throws JFException {
      this.context = context;
      this.console = context.getConsole();
      this.engine = context.getEngine();
      Thread runner = new Thread(new BroadcastLoop());
      runner.start();
   }

   @Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar,
         IBar bidBar) throws JFException {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void onMessage(IMessage message) throws JFException {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void onAccount(IAccount account) throws JFException {
      // TODO Auto-generated method stub
      
   }

   @Override
   public void onStop() throws JFException {
      isRunning=false; // allow for thread loop to exit
      
   }

}


Attachments:
IEngineBroadcastBug.java [3.19 KiB]
Downloaded 114 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: IEngine.broadcast revisited Post rating: 0   New post Posted: Wed 18 Dec, 2013, 14:47 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We managed to replicate this, this will be fixed as soon as available.


 
 Post subject: Re: IEngine.broadcast revisited Post rating: 0   New post Posted: Wed 18 Dec, 2013, 17:43 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
Thanks for fixing it, just to ensure that the fix will work for
my situation of multiple clients in multiple locations in the
same Account.

In my case, there are Strategies running simultaneously
in 3 geographic locations:
On Dukascopy's Remote Live Server, on an Amazon EC2 Linux
server, and on my JForex desktop in the US, all within the same
account. All of these locations are using IEngine.broadcast.

So I am assuming that the pacing solution you'll implement
will enforce a minimum delay between successive messages
on a per-strategy instance basis, within a single IClient
instance.

So long as the Server is not doing any broadcast rejections
on an Account-wide basis, then the solution will be
correct.

Thanks!
HyperScalper


 
 Post subject: Re: IEngine.broadcast revisited Post rating: 0   New post Posted: Sat 21 Dec, 2013, 21:54 

User rating: 1
Joined: Sun 22 Jul, 2012, 13:35
Posts: 40
Hi hyperscalper,

the same problem here. More strategy instances are broadcasting at same time, because there is the same period for open positions and so on. I don´t know how solve this problem. Please dukascopy solve this complication about broadcasting more strategies at same time.


 

Jump to:  

  © 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