API Support Forum
OEC API > API Support > Order is partially filled, then come to Completed state, but then OrderFilledEvent happens.
Author Topic: Order is partially filled, then come to Completed state, but then OrderFilledEvent happens.
(2 messages, Page 1 of 1)
Moderators: VPfau
AAnatoly
Posts: 22
Joined: Jul 01, 2010


Posted: Aug 31, 2010 @ 07:40 AM             Msg. 1 of 2
Please look in the log entries below from ‘Advanced Example’ application

1) Order with 100 lots was send at 13:50:18.059.
It was partly filled 15, 12, 10, 8, 6, 8 - total 59 (OrderFilledEvent called 6 time)

2) Then at 13:50:20.466 State of Order was changed from Working to ‘Completed’.

OrderStateChangedEvent( Order Order, OrderState OldOrderState) was called.
And we checked that: Order.CurrentState = OEC::Data::OrderState::Completed

3) Due documentation Completed status means that no state changes are expected

We check that at this moment filled lots number is still 59 … and there are still 41 not filled lots.
Then we assume that 41 lots will never filled. For example we can think 41 lots were Canceled by User from some application.

But then OrderFilledEvent happens 3 time (filled : 5@4.2125, filled : 19@4.2125 , filled : 17@4.2125)

What is wrong here?
We assume that is order is in ‘Completed state’ that OrderFilledEvent will never called anymore.
If you say that this is ok that OrderFilledEvent is called after ’Completed state’ than how to handle situation when
Order is partly filled and then User send Cancel command? (We are using the same OrderStateChangedEvent )

=========================

Here is a log:

13:50:20.716 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 5@4.2125
13:50:20.637 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 19@4.2125
13:50:20.559 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 17@4.2125
13:50:20.466 : State of Order #201212433 (Sell 100 ZCU0 LMT 4.2125) changed from Working to Completed
13:50:20.387 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 8@4.2125
13:50:20.309 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 6@4.2125
13:50:20.216 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 8@4.2125
13:50:20.122 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 10@4.2125
13:50:20.044 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 12@4.2125
13:50:18.231 : Order #201212433 (Sell 100 ZCU0 LMT 4.2125) filled : 15@4.2125
13:50:18.153 : State of Order #201212433 (Sell 100 ZCU0 LMT 4.2125) changed from Sent to Working
13:50:18.059 : State of Order #201212433 (Sell 100 ZCU0 LMT 4.2125) changed from Unknown to Sent


Anatoly Gutnick
Edited by AAnatoly on Aug 31, 2010 at 07:41:51
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Aug 31, 2010 @ 08:26 AM             Msg. 2 of 2
Hello,

I advise to use the next condition to be sure that an order is finalized:

order.IsFinalState && order.Commands.Pending == null && (order.IsFilled || order.CurrentState == Data.OrderState.Cancelled || order.CurrentState == Data.OrderState.Rejected)

Victor Vins
Software Developer