/// <summary> /// /// </summary> public OrderInfo?SubmitOrder(AccountInfo accountInfo, Symbol symbol, OrderTypeEnum orderType, int volume, decimal?allowedSlippage, decimal?desiredPrice, decimal?takeProfit, decimal?stopLoss, out string operationResultMessage) { OrderInfo?order = null; operationResultMessage = string.Empty; string operationResultMessageCopy = string.Empty; GeneralHelper.DefaultDelegate delegateInstance = delegate() { try { TradeDeskAut desk = _desk; if (desk == null) { return; } bool isBuy = OrderInfo.TypeIsBuy(orderType); double realValue = isBuy ? (double)GetInstrumentData(symbol.Name, "Ask") : (double)GetInstrumentData(symbol.Name, "Bid"); object orderId, psd; object ocoStopOrderId = null, ocoProfitOrderId = null; desk.CreateFixOrder(desk.FIX_OPENMARKET, "", realValue, realValue, (string)GetInstrumentData(symbol.Name, "QuoteID"), accountInfo.Id, symbol.Name, isBuy, volume, "", out orderId, out psd); order = new OrderInfo(orderId.ToString(), symbol, orderType, OrderStateEnum.Executed, volume, new decimal(realValue), null, null, null, null, null, null, null, null, null, null, "ok", "1"); //check bid value... if (stopLoss.HasValue) { double dValue = Decimal.ToDouble(stopLoss.Value); desk.CreateFixOrder(desk.FIX_ENTRYSTOP, "", dValue, dValue, (string)GetInstrumentData(symbol.Name, "QuoteID"), accountInfo.Id, symbol.Name, !isBuy, volume, "", out ocoStopOrderId, out psd); } if (takeProfit.HasValue) { double dValue = Decimal.ToDouble(takeProfit.Value); desk.CreateFixOrder(desk.FIX_ENTRYLIMIT, "", dValue, dValue, (string)GetInstrumentData(symbol.Name, "QuoteID"), accountInfo.Id, symbol.Name, !isBuy, volume, "", out ocoProfitOrderId, out psd); } //Create OCO. if (stopLoss.HasValue && takeProfit.HasValue) { bool creationOk = true; FXCore.OrdersIDEnumAut group = new FXCore.OrdersIDEnumAut(); group.Add((string)ocoProfitOrderId); group.Add((string)ocoStopOrderId); object _result = null; object ocoid = null; desk.CreateOCO(group, out _result, out ocoid); FXCore.OrdersBatchResultEnumAut result = (FXCore.OrdersBatchResultEnumAut)_result; for (int i = 1; i <= result.Count; i++) { FXCore.OrderBatchResultAut res = (FXCore.OrderBatchResultAut)result.Item(i); creationOk = creationOk && res.Success; if (!creationOk) { //Ups throw an exception!!! But what about the current order. } } } } catch (Exception ex) { operationResultMessageCopy = GeneralHelper.GetExceptionMessage(ex); SystemMonitor.OperationError(operationResultMessageCopy); } }; BackgroundMessageLoopOperator messageOperator = _messageLoopOperator; if (messageOperator != null) { messageOperator.Invoke(delegateInstance, TimeSpan.FromSeconds(120)); } operationResultMessage = operationResultMessageCopy; return(order); }
/// <summary> /// /// </summary> public OrderInfo? SubmitOrder(AccountInfo accountInfo, Symbol symbol, OrderTypeEnum orderType, int volume, decimal? allowedSlippage, decimal? desiredPrice, decimal? takeProfit, decimal? stopLoss, out string operationResultMessage) { OrderInfo? order = null; operationResultMessage = string.Empty; string operationResultMessageCopy = string.Empty; GeneralHelper.DefaultDelegate delegateInstance = delegate() { try { TradeDeskAut desk = _desk; if (desk == null) { return; } bool isBuy = OrderInfo.TypeIsBuy(orderType); double realValue = isBuy ? (double)GetInstrumentData(symbol.Name, "Ask") : (double)GetInstrumentData(symbol.Name, "Bid"); object orderId, psd; object ocoStopOrderId = null, ocoProfitOrderId = null; desk.CreateFixOrder(desk.FIX_OPENMARKET, "", realValue, realValue, (string)GetInstrumentData(symbol.Name, "QuoteID"), accountInfo.Id, symbol.Name, isBuy, volume, "", out orderId, out psd); order = new OrderInfo(orderId.ToString(), symbol, orderType, OrderStateEnum.Executed, volume, new decimal(realValue), null, null, null, null, null, null, null, null, null, null, "ok", "1"); //check bid value... if (stopLoss.HasValue) { double dValue = Decimal.ToDouble(stopLoss.Value); desk.CreateFixOrder(desk.FIX_ENTRYSTOP, "", dValue, dValue, (string)GetInstrumentData(symbol.Name, "QuoteID"), accountInfo.Id, symbol.Name, !isBuy, volume, "", out ocoStopOrderId, out psd); } if (takeProfit.HasValue) { double dValue = Decimal.ToDouble(takeProfit.Value); desk.CreateFixOrder(desk.FIX_ENTRYLIMIT, "", dValue, dValue, (string)GetInstrumentData(symbol.Name, "QuoteID"), accountInfo.Id, symbol.Name, !isBuy, volume, "", out ocoProfitOrderId, out psd); } //Create OCO. if (stopLoss.HasValue && takeProfit.HasValue) { bool creationOk = true; FXCore.OrdersIDEnumAut group = new FXCore.OrdersIDEnumAut(); group.Add((string)ocoProfitOrderId); group.Add((string)ocoStopOrderId); object _result = null; object ocoid = null; desk.CreateOCO(group, out _result, out ocoid); FXCore.OrdersBatchResultEnumAut result = (FXCore.OrdersBatchResultEnumAut)_result; for (int i = 1; i <= result.Count; i++) { FXCore.OrderBatchResultAut res = (FXCore.OrderBatchResultAut)result.Item(i); creationOk = creationOk && res.Success; if (!creationOk) { //Ups throw an exception!!! But what about the current order. } } } } catch (Exception ex) { operationResultMessageCopy = GeneralHelper.GetExceptionMessage(ex); SystemMonitor.OperationError(operationResultMessageCopy); } }; BackgroundMessageLoopOperator messageOperator = _messageLoopOperator; if (messageOperator != null) { messageOperator.Invoke(delegateInstance, TimeSpan.FromSeconds(120)); } operationResultMessage = operationResultMessageCopy; return order; }