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.

Can order state change asynchronously in Strategy thread?
 Post subject: Can order state change asynchronously in Strategy thread? Post rating: 0   New post Posted: Thu 19 May, 2011, 19:53 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
Can order state change asynchronously in Strategy thread?

To clarify: Can it be guaranteed that stateA == stateB in the following code?
IOrder.State stateA
IOrder.State stateB
public void onTick(Instrument instrument, ITick tick) throws JFException {
    stateA = order.getState();
    //
    // do other things but
    // remain in Strategy thread and
    // avoid calling order.waitForUpdate()
    //
    stateB = order.getState();
}


 
 Post subject: Re: Can order state change asynchronously in Strategy thread Post rating: 0   New post Posted: Fri 20 May, 2011, 10:40 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
Here is a slightly more practical example:
Suppose I have a conditional order. Because of commission, I want to cancel order, but only if it has not been filled yet.

Will this always work?
if(order.getState() == IOrder.State.OPENED){

     // point A

     order.close();
}

What happens if order gets filled when we reach point A? Will the filled order be closed or will the close be rejected?


 
 Post subject: Re: Can order state change asynchronously in Strategy thread Post rating: 0   New post Posted: Tue 24 May, 2011, 15:09 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Isak wrote:
Can order state change asynchronously in Strategy thread?
To clarify: Can it be guaranteed that stateA == stateB in the following code?

Yes it can be guaranteed. State and other parameters of the IOrder object are changed only in strategy thread.
Isak wrote:
What happens if order gets filled when we reach point A? Will the filled order be closed or will the close be rejected?

If order is in OPEN state then CANCEL message is sent to the server. It is guaranteed that CANCEL message (not CLOSE for filled order) will be sent to the server because you checked the state and it can't be changed from another thread. If server receives a CANCEL message for a filled order then it will reject the CANCEL request. In other words there are different messages for filled and pending orders and you will get ORDER_CLOSE_REJECTED in onMessage method.


 

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