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.

sumbitOrder() inside run()
 Post subject: sumbitOrder() inside run() Post rating: 0   New post Posted: Mon 25 Oct, 2010, 08:24 

User rating: 0
Joined: Wed 20 Oct, 2010, 16:06
Posts: 6
Hello,

A piece of my code is here: https://paste.pocoo.org/show/280297/

The question is: why lines #46 and #47 won't run? When time conditions at #16 are met, the while(true) loop exits and the script proceeds to #44. It prints out "hej" but the sumbitOrder() doesn't work. Does it mean it can't be run inside run()? If so, how can I run them? Time precision is important - that's why I need the run() section.


 
 Post subject: Re: sumbitOrder() inside run() Post rating: 0   New post Posted: Mon 25 Oct, 2010, 08:56 

User rating: 0
Joined: Wed 18 May, 2011, 11:25
Posts: 60
Location: DE
perhaps you have to use the callable object like this:

Future<IOrder> future = context.executeTask(new Callable <IOrder>() {
   public IOrder call() {
      try {
      return context.getEngine().submitOrder("xxx", instrument, IEngine.OrderCommand.SELL, amount, 0, 5, stopOrderPrice, 0);
      }
      catch (JFException e) {
           e.printStackTrace(context.getConsole().getErr());
      return null;
      }
   }
});   
            
try {
   IOrder resultOrder = future.get();
   ...
}
catch (InterruptedException e) {
   e.printStackTrace(context.getConsole().getErr());
}
catch (ExecutionException e) {
   e.printStackTrace(context.getConsole().getErr());
}


 
 Post subject: Re: sumbitOrder() inside run() Post rating: 0   New post Posted: Tue 26 Oct, 2010, 07:50 

User rating: 0
Joined: Wed 20 Oct, 2010, 16:06
Posts: 6
Uh, it looks complicated to me. Is this the only solution? I really don't know how to implement yours.

Please?


 
 Post subject: Re: sumbitOrder() inside run() Post rating: 0   New post Posted: Tue 26 Oct, 2010, 09:39 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
maybe this could help you understand https://www.dukascopy.com/wiki/index.php/Threading


 
 Post subject: Re: sumbitOrder() inside run() Post rating: 0   New post Posted: Tue 26 Oct, 2010, 18:24 

User rating: 0
Joined: Wed 20 Oct, 2010, 16:06
Posts: 6
What should I do with context? Normally when I use it it's inside onStart(IContext context). Where should I get it from to make the above example work? (I just copied the example from Wiki into my code) As for now, I get an error:
17:14:22 context cannot be resolved
17:14:22 ^^^^^^^
17:14:22 context.executeTask(task);
17:14:22 1. ERROR in /tmp/jfxide/tmp/News.java (at line 112)


 

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