public void OnAccountLoaded(MbtAccount account) { this.m_account = account; if (firstTime) { orderLog.Notice("Starting account = " + Display(m_account)); m_position = m_OrderClient.Positions.Find(m_account, symbol.Symbol); if (m_position != null) { orderLog.Notice("Starting position = " + Display(m_position)); } MbtOpenOrders orders = m_OrderClient.OpenOrders; orders.LockItems(); for (int i = 0; i < orders.Count; i++) { orderLog.Notice("Order " + i + ": " + Display(orders[i])); m_orders[orders[i].OrderNumber] = orders[i]; } orders.UnlockItems(); foreach (string orderNum in m_orders.Keys) { string bstrRetMsg = null; if (m_OrderClient.Cancel(orderNum, ref bstrRetMsg) == true) { orderLog.Notice("Order " + orderNum + ": Canceled. " + bstrRetMsg); } else { orderLog.Notice("Order " + orderNum + ": Cancel Failed: " + bstrRetMsg); } } CheckSignalSync(); } firstTime = false; }
bool OrderExecutionSourceStub.IImplementation.CloseOrCancelOrder(AccountInfo accountInfo, string orderId, string orderTag, decimal?allowedSlippage, decimal?desiredPrice, out decimal closingPrice, out DateTime closingTime, out string modifiedId, out string operationResultMessage) { operationResultMessage = string.Empty; closingPrice = 0; closingTime = DateTime.MinValue; modifiedId = orderId; string operationResultMessageLocal = string.Empty; OperationInformation operation = null; GeneralHelper.GenericReturnDelegate <string> operationDelegate = delegate() { operationResultMessageLocal = "Operation not supported."; operation = null; MbtAccount pAcct = GetAccountByInfo(accountInfo); if (pAcct == null) { operationResultMessageLocal = "Failed to retrieve account."; SystemMonitor.OperationWarning(operationResultMessageLocal); return(null); } string message = string.Empty; lock (this) {// Make sure to keep the entire package here locked, since the order operation get placed after the submit // so we need to make sure we shall catch the responce in OnSubmit() too. if (_orderClient.Cancel(orderTag, ref message) == false) {// Error requestMessage. operationResultMessageLocal = message; return(null); } operation = new CancelOrderOperation() { Id = message }; // The message, or operation Id is the order token (further stored in OrderInfo.id) _operationStub.RegisterOperation(operation, false); } return(message); }; object result; if (_messageLoopOperator.Invoke(operationDelegate, TimeSpan.FromSeconds(8), out result) == false) {// Timed out. operationResultMessage = "Timeout submiting order cancelation."; return(false); } if (string.IsNullOrEmpty((string)result)) {// Operation error. operationResultMessage = operationResultMessageLocal; return(false); } // Return the ID of the submitted order. return(true); }