API Support Forum
OEC API > API Support > Order States
Author Topic: Order States
(16 messages, Page 1 of 1)
Moderators: VPfau
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 03:03 PM             Msg. 1 of 16
This question is strictly related to the OnOrderStatus event.

Order states of a scenario:
-Working
-Working + pendingcommandtypestate = cancel sent (Pending cancel)
-Completed + LastCommandState=Executed (what order state is this?)

From the OnOrderStatus event, how can we determine whether the order was Filled or Canceled?
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 03:08 PM             Msg. 2 of 16
When order state is "Completed" - order is completed regardless of LastCommandState. The LastCommand can be used only for pending requests.

Order is filled when Order.State = Working and Fills.TotalQuantity = Order.Quantity.
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 03:13 PM             Msg. 3 of 16
Correct me if I am wrong but we cannot rely on Fills.TotalQuantity from the OnOrderStatus event: if the order was just filled the Fills.TotalQuantity value will not reflect the real filled quantity.
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 03:25 PM             Msg. 4 of 16
There is a possiblity that order becomes completed before fills are received for electronic orders.
Pit orders are filled and then completed.
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 03:43 PM             Msg. 5 of 16
OK that solves the problem for pits.

Usually we get the OnOrderStatus event before the OnOrderFilled event so the OnOrderStatus->Fills.TotalQuantity will be zero. So back to my original question: how can we determine whether the order was filled or canceled? In both cases we'll get CurrentState=Completed..
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 03:48 PM             Msg. 6 of 16
for electronic orders you can be sure if orderstate is completed, order has fills or will have them soon.
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 04:04 PM             Msg. 7 of 16
I think we are talking past each other, a scenario should help:

Below are exchange order states.

Scenario1:
1) New (buy 1)
2) Pending_Cancel
3) Filled

Scenario2:
1) New (buy 1)
2) Pending_Cancel
3) Canceled

When the last event arrives in the onOrderStatus event handler, we get CurrentStatus = Completed in both scenarios.

For pits you said we would already have received the onFilled event and therefore I assume (correctly?) the API.Order object will have been updated by your API. We can therefore determine whether the order was canceled by checking that onOrderStatus .Order.Fills.TotalQuantity < Order.Quantity.

For electronics, the fill may not have been processed in your API so onOrderStatus .Order.Fills.TotalQuantity may be zero or 1. (usually zero), so how do we know if it was 100% filled or canceled?
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 04:10 PM             Msg. 8 of 16
in the scenario 2 step 3 you will get currentstate = Cancelled, not completed.

if you had an order behaves differently, please send the order ticket number to us.
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 04:20 PM             Msg. 9 of 16
If we cancel a partially filled order, what is the last OrderState?
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 04:24 PM             Msg. 10 of 16
in this case it would be completed.
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 04:28 PM             Msg. 11 of 16
So again back to my original question: in this case what does Completed mean?

Canceled or Filled? Remember for electronics we cannot rely on the TotalQuantity property.
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 04:34 PM             Msg. 12 of 16
if you have partial fills and order state is completed, you may consider it was cancelled.
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 04:44 PM             Msg. 13 of 16
How can we tell it was partially filled? Again the TotalQuantity may be zero even if the order is part filled for electronics.
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 10, 2007 @ 04:48 PM             Msg. 14 of 16
if order wasn't, it will become "cancelled".
FGingras
Posts: 36
Joined: Oct 15, 2007


Posted: Dec 10, 2007 @ 05:06 PM             Msg. 15 of 16
This is a circular argument.

Say we try to cancel an order. We then get a onOrderStatus event.

If CurrentStatus = Canceled ->order is canceled. This only occurs if the order has no fills.

If CurrentStatus = Completed -> order may be filled or canceled.

We have no way of knowing if it was part filled because we have not received the fill yet, so what does CurrentStatus = Completed mean?

Am I missing something?
SergeK
-Developer-
Posts: 475
Joined: Jan 26, 2007


Posted: Dec 11, 2007 @ 08:40 AM             Msg. 16 of 16
in OEC terms, completed means order is done for day and has some fills. it doesn't matter for us whether it was fully filled or partially filled and then cancelled.

in your terms, you need to know whether the order was cancelled or partially filled - which is not always possible in the state event, because not all fills are received.