The order during it’s life goes through the following states:
- OrderStates.None - the order has been created in the algorithm and has not been sent to the registration.
- OrderStates.Pending - the order has been sent to the registration (Connector.RegisterOrder(StockSharp.BusinessEntities.Order order)) and the ITransactionProvider.NewOrder event for it has been called. The confirmation of the order acceptance from the exchange is expected. If successful, the Connector.OrderChanged, event will be called and the order will be changed to the OrderStates.Active state. Also the Order.Id and Order.Time properties will be initialized. In the case of the order rejection the Connector.OrderRegisterFailed event with the error description will be called and the order will be changed to the OrderStates.Failed state.
- OrderStates.Active - the order is active on exchange. Such order will be active as long as all of the order Order.Volume volume is matched, or it will be forcibly cancelled through ITransactionProvider.CancelOrder(StockSharp.BusinessEntities.Order order). If the order matched partially the ITransactionProvider.NewMyTrade events about new trades on issued order have been called, as well as the Connector.OrderChanged event, which the Order.Balance notification about the order balance change passed. The latest event will be arised in the case of the order cancellation.
- OrderStates.Done - the order is no longer active on the exchange (been fully matched or cancelled).
- OrderStates.Failed - the order has not been accepted by the exchange (or intermediate system, such as the broker server) for any reason.
To find out the order trading state (what volume is matched, whether the order fully matched, and so on) the TraderHelper.IsCanceled(StockSharp.BusinessEntities.Order order), TraderHelper.IsMatchedEmpty(StockSharp.BusinessEntities.Order order), TraderHelper.IsMatchedPartially(StockSharp.BusinessEntities.Order order), TraderHelper.IsMatched(StockSharp.BusinessEntities.Order order) and TraderHelper.GetMatchedVolume(StockSharp.BusinessEntities.Order order) methods should be used:
// any order Order order = .... // is the order was cancelled Console.WriteLine(order.IsCanceled()); // or fully matched Console.WriteLine(order.IsMatched()); // or just partially Console.WriteLine(order.IsMatchedPartially()); // or non of any contracts was matched Console.WriteLine(order.IsMatchedEmpty()); // so we are getting the realized (=matched) order size. Console.WriteLine(order.GetMatchedVolume());