示例#1
0
        public bool ExecuteMarketOrder(AccountInfo accountInfo, Symbol symbol, OrderTypeEnum orderType, int volume,
                                       decimal?allowedSlippage, decimal?desiredPrice, decimal?takeProfit, decimal?stopLoss,
                                       string comment, out OrderInfo?orderPlaced, out string operationResultMessage)
        {
            orderPlaced = null;

            FXCMConnectionManager manager = Manager;

            if (manager == null)
            {
                operationResultMessage = "Order system not ready to operate.";
                return(false);
            }

            orderPlaced = manager.SubmitOrder(accountInfo, symbol, orderType, volume, allowedSlippage, desiredPrice,
                                              takeProfit, stopLoss, out operationResultMessage);


            if (orderPlaced.HasValue)
            {
                lock (this)
                {
                    _orders[orderPlaced.Value.Id] = orderPlaced.Value;
                }
                return(true);
            }
            else
            {
                return(false);
            }

            //operationResultMessage = string.Empty;
            //string operationResultMessageCopy = string.Empty;

            //bool isBuy = OrderInfo.TypeIsBuy(orderType);

            //OrderInfo? order = null;
            //GeneralHelper.GenericReturnDelegate<bool> operationDelegate = delegate()
            //{
            //    double realValue = (double)_adapter.GetInstrumentData(symbol.Name, "Ask");
            //    if (!isBuy)
            //    {
            //        realValue = (double)_adapter.GetInstrumentData(symbol.Name, "Bid");
            //    }

            //    try
            //    {
            //        order = CreateOrder(accountInfo,
            //                                symbol,
            //                                orderType,
            //                                volume,
            //                                allowedSlippage,
            //                                desiredPrice,
            //                                takeProfit,
            //                                stopLoss);
            //    }
            //    catch (Exception ex)
            //    {
            //        operationResultMessageCopy = ex.Message;
            //        return false;
            //    }

            //    return true;
            //};

            //orderPlaced = order;

            //object result;
            //if (_messageLoopOperator.Invoke(operationDelegate, TimeSpan.FromSeconds(120), out result) == false)
            //{// Timed out.
            //    operationResultMessage = "Timeout submiting order.";
            //    return false;
            //}

            //if (!(bool)result)
            //{// Operation error.
            //    operationResultMessage = operationResultMessageCopy;
            //    return false;
            //}

            //orderPlaced = order;

            //return true;
        }