Can order state change asynchronously in Strategy thread?
Isak
Post subject: Can order state change asynchronously in Strategy thread?
Post rating: 0
Posted: Thu 19 May, 2011, 19:53
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(); }
Isak
Post subject: Re: Can order state change asynchronously in Strategy thread
Post rating: 0
Posted: Fri 20 May, 2011, 10:40
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?
API Support
Post subject: Re: Can order state change asynchronously in Strategy thread
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.