/// <summary> /// /// </summary> public bool SynchronousExecute(AccountInfo account, Order order, Symbol symbol, OrderTypeEnum orderType, int volume, decimal?allowedSlippage, decimal?desiredPrice, decimal?takeProfit, decimal?stopLoss, string comment, TimeSpan operationTimeOut, out OrderInfo?info, out string operationResultMessage) { info = null; OrderInfo updatedInfo = order.Info; updatedInfo.OpenPrice = null; updatedInfo.OpenTime = null; updatedInfo.State = OrderStateEnum.Unknown; IQuoteProvider quotes; IDataBarHistoryProvider bars; if (GetProviders(symbol, out quotes, out bars) == false) { operationResultMessage = "Failed to establish corresponding providers."; return(false); } if (quotes.OperationalState != OperationalStateEnum.Operational || quotes.Ask.HasValue == false || quotes.Bid.HasValue == false || quotes.Time.HasValue == false) { operationResultMessage = "Data provider not operational or not providing valid dataDelivery."; return(false); } decimal?currentPrice = quotes.GetOrderOpenQuote(orderType); if (desiredPrice.HasValue && allowedSlippage.HasValue && currentPrice.HasValue && allowedSlippage > 0 && Math.Abs(currentPrice.Value - desiredPrice.Value) > allowedSlippage) {// Slippage requirements failed. operationResultMessage = "Slippage criteria not met."; return(false); } operationResultMessage = string.Empty; updatedInfo.OpenTime = quotes.Time.Value; if (orderType == OrderTypeEnum.BUY_MARKET || orderType == OrderTypeEnum.SELL_MARKET) {// Immediate order. updatedInfo.State = OrderStateEnum.Executed; updatedInfo.OpenPrice = currentPrice; } else {// Delayed pending order. //updatedInfo.State = OrderStateEnum.Submitted; //updatedInfo.OpenPrice = desiredPrice; operationResultMessage = "Order type not currently supported in back testing mode."; return(false); } updatedInfo.StopLoss = stopLoss; updatedInfo.TakeProfit = takeProfit; updatedInfo.Comment = comment; updatedInfo.Type = orderType; updatedInfo.Symbol = symbol; updatedInfo.Volume = volume; updatedInfo.Id = (_pendingOrderId++).ToString(); if (UpdatePosition(symbol, OrderInfo.TypeIsBuy(updatedInfo.Type) ? volume : -volume, out operationResultMessage) == false) { return(false); } info = updatedInfo; lock (this) { _orders.Add(updatedInfo.Id, order); } BeginAccountInfoUpdate(_account.Info); BeginManagedOrdersUpdate(_lastDataQuote); //RaiseOrderUpdateEvent(updatedInfo, Order.UpdateTypeEnum.Executed); return(true); }