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.

Must orderUpdateWait() be run from strategy thread?
 Post subject: Must orderUpdateWait() be run from strategy thread? Post rating: 1   New post Posted: Sat 31 May, 2014, 15:01 
User avatar

User rating: 11
Joined: Tue 27 Mar, 2012, 17:47
Posts: 111
Location: GermanyGermany
Hello Support,

must the method orderUpdateWait(long, State) be executed on the strategy thread?
Currently I run it from a separate thread but I'm not sure if the waiting time gets actually executed.
Is there a list of all methods which must be run from the strategy thread?

Thanks,
Juergen


 
 Post subject: Re: Must orderUpdateWait() be run from strategy thread? Post rating: 0   New post Posted: Mon 02 Jun, 2014, 12:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
FXjuxe wrote:
must the method orderUpdateWait(long, State) be executed on the strategy thread?
It is not mandatory, consider the following example:
package jforex.orders;

import com.dukascopy.api.*;
import com.dukascopy.api.util.DateUtils;
import com.dukascopy.api.IEngine.OrderCommand;

public class WaitForUpdateAnotherThread implements IStrategy {
   
    private IConsole console;

    public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
        context.setSubscribedInstruments(java.util.Collections.singleton(Instrument.EURUSD), true);
        final IOrder order = context.getEngine().submitOrder("MarketOrder", Instrument.EURUSD, OrderCommand.BUY, 0.1);
        print("after submit " + order);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    print("before wait " + order);
                    order.waitForUpdate(12000, IOrder.State.FILLED);
                    print("after wait " + order);
                } catch (JFException e) {
                    e.printStackTrace();
                }
            }
        }) {
        }.start();
        print("after starting other thread " + order);
    }
   
    private void print(Object o){
        console.getOut().println(Thread.currentThread().getName() + " " + DateUtils.format(System.currentTimeMillis()) + " " + o);
    }
   
    @Override
    public void onMessage(IMessage message) throws JFException {
        if(message.getOrder() != null){
            console.getInfo().println(message);
        }
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

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

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

    @Override
    public void onStop() throws JFException {}

}


FXjuxe wrote:
Currently I run it from a separate thread but I'm not sure if the waiting time gets actually executed.
Consider checking it in a similar fashion as we did in our example.
FXjuxe wrote:
Is there a list of all methods which must be run from the strategy thread?
All order creation/modification methods.


 

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