/// <summary> /// /// </summary> protected override string OnExecuteMarket(ISourceOrderExecution provider, OrderTypeEnum orderType, int volume, decimal? price, decimal? slippage, decimal? takeProfit, decimal? stopLoss, TimeSpan timeOut, out PositionExecutionInfo executionInfo, out string operationResultMessage) { SystemMonitor.CheckError(provider.SupportsActiveOrderManagement, "Wrong position type for this provider."); executionInfo = PositionExecutionInfo.Empty; IQuoteProvider quoteProvider = _manager.ObtainQuoteProvider(_dataDelivery.SourceId, Symbol); if (quoteProvider == null) { operationResultMessage = "Failed to establish quote provider for [" + _dataDelivery.SourceId.Name + ", " + Symbol.Name + "]."; SystemMonitor.Error(operationResultMessage); return string.Empty; } price = ProcessPrice(quoteProvider, orderType, price); // New order shall be created. ActiveOrder order = new ActiveOrder(_manager, provider, quoteProvider, _dataDelivery.SourceId, Symbol, true); OrderInfo? infoReference; // Using the extended operationTimeOut to 40 seconds. bool result = provider.SynchronousExecute(provider.DefaultAccount.Info, order, _info.Symbol, orderType, volume, slippage, price, takeProfit, stopLoss, string.Empty, TimeSpan.FromSeconds(40), out infoReference, out operationResultMessage); if (result && infoReference.HasValue) { OrderInfo infoAssign = infoReference.Value; if (infoAssign.Type == OrderTypeEnum.UNKNOWN) { infoAssign.Type = orderType; } if (infoAssign.Volume == int.MinValue || infoAssign.Volume == int.MaxValue) {// Volume was not retrieved by integration. infoAssign.Volume = volume; } if (infoAssign.OpenPrice.HasValue) { executionInfo = new PositionExecutionInfo(infoReference.Value.Id, _dataDelivery.SourceId, provider.SourceId, Symbol, infoAssign.Type, infoAssign.OpenPrice.Value, volume, volume, infoAssign.OpenTime, PositionExecutionInfo.ExecutionResultEnum.Success); } else { SystemMonitor.Error("Received execution result, but price not assigned."); } order.AdoptInfo(infoAssign); provider.TradeEntities.AddOrder(order); return infoReference.Value.Id; } return string.Empty; }
/// <summary> /// /// </summary> protected override string OnExecuteMarket(ISourceOrderExecution provider, OrderTypeEnum orderType, int volume, decimal?price, decimal?slippage, decimal?takeProfit, decimal?stopLoss, TimeSpan timeOut, out PositionExecutionInfo executionInfo, out string operationResultMessage) { SystemMonitor.CheckError(provider.SupportsActiveOrderManagement == false, "Wrong position type for this provider."); executionInfo = PositionExecutionInfo.Empty; PassiveOrder order; lock (this) { order = new PassiveOrder(_manager, _dataDelivery.SourceId, provider.SourceId); } OrderInfo?infoReference; bool result = provider.SynchronousExecute(provider.DefaultAccount.Info, order, _info.Symbol, orderType, volume, slippage, price, takeProfit, stopLoss, string.Empty, out infoReference, out operationResultMessage); if (result && infoReference.HasValue) { OrderInfo infoAssign = infoReference.Value; if (infoAssign.Type == OrderTypeEnum.UNKNOWN) { infoAssign.Type = orderType; } if (infoAssign.Volume == int.MinValue || infoAssign.Volume == int.MaxValue) {// Volume was not retrieved by integration. infoAssign.Volume = volume; } if (infoAssign.OpenPrice.HasValue) { executionInfo = new PositionExecutionInfo(infoReference.Value.Id, _dataDelivery.SourceId, provider.SourceId, Symbol, infoAssign.Type, infoAssign.OpenPrice.Value, volume, volume, infoAssign.OpenTime, PositionExecutionInfo.ExecutionResultEnum.Success); } else { SystemMonitor.Error("Received execution result, but price not assigned."); } order.AdoptInfo(infoAssign); provider.TradeEntities.AddOrder(order); return(infoReference.Value.Id); } return(string.Empty); }
/// <summary> /// /// </summary> protected override string OnExecuteMarket(ISourceOrderExecution provider, OrderTypeEnum orderType, int volume, decimal? price, decimal? slippage, decimal? takeProfit, decimal? stopLoss, TimeSpan timeOut, out PositionExecutionInfo executionInfo, out string operationResultMessage) { SystemMonitor.CheckError(provider.SupportsActiveOrderManagement == false, "Wrong position type for this provider."); executionInfo = PositionExecutionInfo.Empty; PassiveOrder order; lock (this) { order = new PassiveOrder(_manager, _dataDelivery.SourceId, provider.SourceId); } OrderInfo? infoReference; bool result = provider.SynchronousExecute(provider.DefaultAccount.Info, order, _info.Symbol, orderType, volume, slippage, price, takeProfit, stopLoss, string.Empty, out infoReference, out operationResultMessage); if (result && infoReference.HasValue) { OrderInfo infoAssign = infoReference.Value; if (infoAssign.Type == OrderTypeEnum.UNKNOWN) { infoAssign.Type = orderType; } if (infoAssign.Volume == int.MinValue || infoAssign.Volume == int.MaxValue) {// Volume was not retrieved by integration. infoAssign.Volume = volume; } if (infoAssign.OpenPrice.HasValue) { executionInfo = new PositionExecutionInfo(infoReference.Value.Id, _dataDelivery.SourceId, provider.SourceId, Symbol, infoAssign.Type, infoAssign.OpenPrice.Value, volume, volume, infoAssign.OpenTime, PositionExecutionInfo.ExecutionResultEnum.Success); } else { SystemMonitor.Error("Received execution result, but price not assigned."); } order.AdoptInfo(infoAssign); provider.TradeEntities.AddOrder(order); return infoReference.Value.Id; } return string.Empty; }
/// <summary> /// /// </summary> protected override string OnExecuteMarket(ISourceOrderExecution provider, OrderTypeEnum orderType, int volume, decimal?price, decimal?slippage, decimal?takeProfit, decimal?stopLoss, TimeSpan timeOut, out PositionExecutionInfo executionInfo, out string operationResultMessage) { SystemMonitor.CheckError(provider.SupportsActiveOrderManagement, "Wrong position type for this provider."); executionInfo = PositionExecutionInfo.Empty; IQuoteProvider quoteProvider = _manager.ObtainQuoteProvider(_dataDelivery.SourceId, Symbol); if (quoteProvider == null) { operationResultMessage = "Failed to establish quote provider for [" + _dataDelivery.SourceId.Name + ", " + Symbol.Name + "]."; SystemMonitor.Error(operationResultMessage); return(string.Empty); } price = ProcessPrice(quoteProvider, orderType, price); // New order shall be created. ActiveOrder order = new ActiveOrder(_manager, provider, quoteProvider, _dataDelivery.SourceId, Symbol, true); OrderInfo?infoReference; // Using the extended operationTimeOut to 40 seconds. bool result = provider.SynchronousExecute(provider.DefaultAccount.Info, order, _info.Symbol, orderType, volume, slippage, price, takeProfit, stopLoss, string.Empty, TimeSpan.FromSeconds(40), out infoReference, out operationResultMessage); if (result && infoReference.HasValue) { OrderInfo infoAssign = infoReference.Value; if (infoAssign.Type == OrderTypeEnum.UNKNOWN) { infoAssign.Type = orderType; } if (infoAssign.Volume == int.MinValue || infoAssign.Volume == int.MaxValue) {// Volume was not retrieved by integration. infoAssign.Volume = volume; } if (infoAssign.OpenPrice.HasValue) { executionInfo = new PositionExecutionInfo(infoReference.Value.Id, _dataDelivery.SourceId, provider.SourceId, Symbol, infoAssign.Type, infoAssign.OpenPrice.Value, volume, volume, infoAssign.OpenTime, PositionExecutionInfo.ExecutionResultEnum.Success); } else { SystemMonitor.Error("Received execution result, but price not assigned."); } order.AdoptInfo(infoAssign); provider.TradeEntities.AddOrder(order); return(infoReference.Value.Id); } return(string.Empty); }