/// <summary> /// Changes the state of the Working Order to reflect a filledly filled state. /// </summary> private static void OnFilledAction(Object[] key, params Object[] parameters) { // A middle tier context is also required for a transacted update. DataModelTransaction dataModelTransaction = DataModelTransaction.Current; // It is possible that the Working Order that is the object of this status update operation may have been deleted since the action was // created. This is not an error condition. If there is no Working Order to update, then the operation is just terminated prematurely. WorkingOrderRow workingOrderRow = DataModel.WorkingOrder.WorkingOrderKey.Find(key); if (workingOrderRow == null) { return; } workingOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout); dataModelTransaction.AddLock(workingOrderRow); if (workingOrderRow.RowState == DataRowState.Detached) { return; } // The error status on a Working Order cannot be cleared with a fill. if (workingOrderRow.StatusId != StatusMap.FromCode(Status.Error)) { // The Working Order is 'Filled' when the quantity executed is the same as the quantity ordered. Decimal quantityOrdered = WorkingOrder.GetSourceOrderQuantity(dataModelTransaction, workingOrderRow); Decimal quantityExecuted = WorkingOrder.GetExecutionQuantity(dataModelTransaction, workingOrderRow); if (quantityOrdered == quantityExecuted) { UpdateWorkingOrderStatus(workingOrderRow, Status.Filled); } } }
/// <summary> /// Changes the state of the Working Order to reflect a filledly filled state. /// </summary> private static void ClearErrorAction(Object[] key, params Object[] parameters) { // A middle tier context is also required for a transacted update. DataModelTransaction dataModelTransaction = DataModelTransaction.Current; // It is possible that the Working Order that is the object of this status update operation may have been deleted since the action was // created. This is not an error condition. If there is no Working Order to update, then the operation is just terminated prematurely. WorkingOrderRow workingOrderRow = DataModel.WorkingOrder.WorkingOrderKey.Find(key); if (workingOrderRow == null) { return; } workingOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout); dataModelTransaction.AddLock(workingOrderRow); if (workingOrderRow.RowState == DataRowState.Detached) { return; } // The 'Error' status is only cleared when all the Destination Orders are valid. Boolean isErrorStatus = false; foreach (DestinationOrderRow siblingOrderRow in workingOrderRow.GetDestinationOrderRows()) { siblingOrderRow.AcquireReaderLock(dataModelTransaction); if (siblingOrderRow.StatusId == StatusMap.FromCode(Status.Error)) { isErrorStatus = true; break; } } // The proper Working Order status must be evaluated when the error status is cleared. if (!isErrorStatus) { // The aggregates will determine the new state of the Working Order. Decimal quantityExecuted = WorkingOrder.GetExecutionQuantity(dataModelTransaction, workingOrderRow); Decimal quantityOrdered = WorkingOrder.GetSourceOrderQuantity(dataModelTransaction, workingOrderRow); // This restores the 'New' status when the canceled Destination Order was the only order with any fills. if (quantityExecuted == 0.0M && workingOrderRow.StatusId != StatusMap.FromCode(Status.New)) { UpdateWorkingOrderStatus(workingOrderRow, Status.New); } // This restores the 'Partially Filled' status when other executions remain. if (0.0M < quantityExecuted && quantityExecuted < quantityOrdered && workingOrderRow.StatusId != StatusMap.FromCode(Status.PartiallyFilled)) { UpdateWorkingOrderStatus(workingOrderRow, Status.PartiallyFilled); } // This restores the 'Filled' status when the quantity executed is the same as the quantity ordered. if (quantityExecuted == quantityOrdered && workingOrderRow.StatusId != StatusMap.FromCode(Status.Filled)) { UpdateWorkingOrderStatus(workingOrderRow, Status.Filled); } } }