/// <summary>
        /// Will calculate the result of this execution up until now, against the values of the provider.
        /// </summary>
        /// <param name="provider"></param>
        /// <returns></returns>
        public decimal?GetPendingResult(IQuoteProvider provider, Order.ResultModeEnum mode, DataSessionInfo info)
        {
            if (this.IsEmpty || _executedPrice.HasValue == false || this._executedPrice == 0 || provider == null)
            {
                return(null);
            }

            return(Order.GetResult(mode, _executedPrice, null, _volumeExecuted, Symbol, OrderStateEnum.Executed, OrderType, null, Symbol.Empty,
                                   info.LotSize, info.DecimalPlaces, provider.Ask, provider.Bid));
        }
Exemple #2
0
        /// <summary>
        /// Calculate order result.
        /// </summary>
        public virtual decimal?GetResult(ResultModeEnum mode)
        {
            ISourceOrderExecution executionProvider = _executionProvider;

            if (executionProvider == null || executionProvider.OperationalState != OperationalStateEnum.Operational ||
                QuoteProvider == null || QuoteProvider.OperationalState != OperationalStateEnum.Operational ||
                SessionInfo.HasValue == false ||
                this.Account == null)
            {
                return(null);
            }

            if (State != OrderStateEnum.Executed)
            {
                // TODO : verify the calculation and usage of the results in other states.
                // There was a blocking call on the Order.GetResult that prevented all
                // other states from receiving results.
                return(null);
            }

            return(Order.GetResult(mode, this.OpenPrice, this.ClosePrice, this.CurrentVolume, this.Symbol, this.State, this.Type,
                                   CurrencyConversionManager.Instance, this.Account.Info.BaseCurrency, SessionInfo.Value.LotSize,
                                   SessionInfo.Value.DecimalPlaces, QuoteProvider.Ask, QuoteProvider.Bid));
        }
        /// <summary>
        /// NON UI Thread.
        /// </summary>
        //protected void DoObtainAllOrders(bool showError)
        //{
        //foreach (ExpertSession session in _sessions.ToArray())
        //{
        //    if (session.OrderExecutionProvider == null ||
        //        session.OrderExecutionProvider.OperationalState != OperationalStateEnum.Operational)
        //    {
        //        continue;
        //    }
        //    string operationResultMessage;
        //    if (session.OrderExecutionProvider.DefaultAccount != null &&
        //        session.OrderExecutionProvider.DefaultAccount.SynchronizeOrders(null, out operationResultMessage) == false)
        //    {
        //        if (showError)
        //        {
        //            MessageBox.Show("Failed to obtain orders session [" + session.Info.Name + "] [" + operationResultMessage + "].", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //        }
        //        else
        //        {
        //            SystemMonitor.OperationError("Failed to obtain orders session [" + session.Info.Name + "] [" + operationResultMessage + "].");
        //        }
        //    }
        //}
        //WinFormsHelper.BeginFilteredManagedInvoke(this, new GeneralHelper.DefaultDelegate( delegate() { toolStripButtonObtainOrders.Enabled = true; }));
        //}
        protected ListViewItem SetItemAsOrder(ListViewItem item, Order order, AccountInfo account)
        {
            if (item.Tag != order)
            {
                item.Tag = order;
            }

            if (item.UseItemStyleForSubItems != false)
            {
                item.UseItemStyleForSubItems = false;
            }

            OrderStateEnum orderState = order.State;
            string groupName = string.Format("{0} Orders, Server [{1}] Company [{2}] Account [{3} / {4}]", orderState.ToString().ToUpper(), account.Server, account.Company, account.Name, account.Id);

            ListViewGroup group = listViewOrders.Groups[groupName];
            if (group == null)
            {
                group = new ListViewGroup(groupName, groupName);

                if (orderState == OrderStateEnum.Executed)
                {// Insert group at top of list.
                    listViewOrders.Groups.Insert(0, group);
                }
                else if (orderState == OrderStateEnum.Submitted)
                {// ...
                    listViewOrders.Groups.Insert(0, group);
                }
                else
                {
                    listViewOrders.Groups.Add(group);
                }
            }

            if (item.Group != group)
            {
                item.Group = group;
            }

            if (order.IsBuy)
            {
                int index = order.State == OrderStateEnum.Executed ? 0 : 2;
                if (item.ImageIndex != index)
                {
                    item.ImageIndex = index;
                }
            }
            else
            {
                int index = order.State == OrderStateEnum.Executed ? 1 : 3;
                if (item.ImageIndex != index)
                {
                    item.ImageIndex = index;
                }
            }

            while(item.SubItems.Count < 12)
            {
                item.SubItems.Add("");
            }

            //if (order.Type == OrderTypeEnum.UNKNOWN)
            //{// Order type not established yet.
            //    item.SubItems[0].Text = "NA";
            //    return item;
            //}

            string id = order.Id;
            if (id == null)
            {
                id = string.Empty;
            }

            if (item.SubItems[0].Text != id)
            {
                item.SubItems[0].Text = id;
            }

            if (item.SubItems[1].Text != order.Symbol.Name)
            {
                item.SubItems[1].Text = order.Symbol.Name;
            }

            if (order.IsOpenOrPending)
            {
                if (item.SubItems[2].Text != (GeneralHelper.GetShortDateTime(order.OpenTime)))
                {
                    item.SubItems[2].Text = (GeneralHelper.GetShortDateTime(order.OpenTime));
                }
            }
            else
            {
                if (item.SubItems[2].Text != (GeneralHelper.GetShortDateTime(order.OpenTime) + " to " + GeneralHelper.GetShortDateTime(order.CloseTime)))
                {
                    item.SubItems[2].Text = (GeneralHelper.GetShortDateTime(order.OpenTime) + " to " + GeneralHelper.GetShortDateTime(order.CloseTime));
                }
            }

            if (item.SubItems[3].Text != (order.Type.ToString()))
            {
                item.SubItems[3].Text = (order.Type.ToString());
            }

            if (item.SubItems[4].Text != (GeneralHelper.ToString(order.CurrentVolume)))
            {
                item.SubItems[4].Text = GeneralHelper.ToString(order.CurrentVolume);
            }

            if (item.SubItems[5].Text != GeneralHelper.ToString(order.OpenPrice))
            {
                item.SubItems[5].Text = GeneralHelper.ToString(order.OpenPrice);
            }

            string closePriceValue = GeneralHelper.ToString(order.ClosePrice);
            if (item.SubItems[6].Text != closePriceValue)
            {
                item.SubItems[6].Text = closePriceValue;
            }

            if (item.SubItems[7].Text != GeneralHelper.ToString(order.StopLoss))
            {
                item.SubItems[7].Text = GeneralHelper.ToString(order.StopLoss);
            }

            if (item.SubItems[8].Text != GeneralHelper.ToString(order.TakeProfit))
            {
                item.SubItems[8].Text = GeneralHelper.ToString(order.TakeProfit);
            }

            if (item.SubItems[9].Text != ("-"))
            {
                item.SubItems[9].Text = ("-");
            }

            decimal? currentResultPips = order.GetResult(Order.ResultModeEnum.Pips);
            decimal? currentResultBaseCurrency = order.GetResult(Order.ResultModeEnum.Currency);

            string resultString;

            if (currentResultBaseCurrency.HasValue == false ||
                currentResultBaseCurrency.HasValue == false)
            {
                resultString = "NaN";
            }
            else
            {
                resultString = currentResultPips.Value.ToString("0.#") + "p / " + currentResultBaseCurrency.Value.ToString("0.#");
            }

            if (item.SubItems[10].Text != resultString)
            {
                item.SubItems[10].Text = resultString;
            }

            if (currentResultPips < 0)
            {
                if (item.SubItems[10].BackColor != Color.MistyRose)
                {
                    item.SubItems[10].BackColor = Color.MistyRose;
                }
            }
            else
            {
                if (item.SubItems[10].BackColor != Color.Transparent)
                {
                    item.SubItems[10].BackColor = Color.Transparent;
                }
            }

            if (item.SubItems[11].Text != "-")
            {
                item.SubItems[11].Text = ("-");
            }

            return item;
        }
Exemple #4
0
        /// <summary>
        /// Calculate order result.
        /// </summary>
        public override decimal?GetResult(ResultModeEnum mode)
        {
            ISourceOrderExecution executionProvider = _executionProvider;

            if (executionProvider == null || executionProvider.OperationalState != OperationalStateEnum.Operational ||
                _quoteProvider == null || _quoteProvider.OperationalState != OperationalStateEnum.Operational ||
                SessionInfo.HasValue == false ||
                this.Account == null)
            {
                return(null);
            }

            if (State != OrderStateEnum.Executed)
            {
                // TODO : verify the calculation and usage of the results in other states.
                // There was a blocking call on the Order.GetResult that prevented all
                // other states from receiving results.
                return(null);
            }

            return(Order.GetResult(mode, this.OpenPrice, this.ClosePrice, this.CurrentVolume, this.Symbol, this.State, this.Type,
                                   CurrencyConversionManager.Instance, this.Account.Info.BaseCurrency, SessionInfo.Value.LotSize,
                                   SessionInfo.Value.DecimalPlaces, _quoteProvider.Ask, _quoteProvider.Bid));

            //decimal? currentRawResult = null;
            //if (State == OrderStateEnum.Executed)
            //{
            //    if (State != OrderStateEnum.Executed || OpenPrice.HasValue == false)
            //    {// Failed to get result.
            //        currentRawResult = 0;
            //    }
            //    else
            //    {
            //        // Update result.
            //        currentRawResult = GetRawResult(this.OpenPrice, this.CurrentVolume, this.State, this.Type,
            //            executionProvider.QuoteProvider.Ask, executionProvider.QuoteProvider.Bid, mode != ResultModeEnum.Pips);
            //    }

            //    lock (this)
            //    {
            //        //_currentRawResult = currentRawResult;
            //        _orderMaximumResultAchieved = Math.Max(_orderMaximumResultAchieved, currentRawResult.HasValue ? currentRawResult.Value : 0);
            //    }
            //}

            //if (currentRawResult.HasValue == false)
            //{
            //    return null;
            //}

            //int decimalPlaces = (int)executionProvider.Info.DecimalPlaces;
            //decimal lotSize = executionProvider.Info.LotSize;
            //decimal currency = currentRawResult.Value * lotSize;

            //lock (this)
            //{
            //    if (mode == ResultModeEnum.Pips)
            //    {
            //        if (State == OrderStateEnum.Closed)
            //        {// When closed we need to compensate the
            //            if (IsBuy)
            //            {
            //                return (_info.ClosePrice - _info.OpenPrice) * (decimal)Math.Pow(10, decimalPlaces);
            //            }
            //            else
            //            {
            //                return (_info.OpenPrice - _info.ClosePrice) * (decimal)Math.Pow(10, decimalPlaces);
            //            }
            //        }
            //        else
            //        {
            //            return currentRawResult.Value * (decimal)Math.Pow(10, decimalPlaces);
            //        }
            //    }
            //    else if (mode == ResultModeEnum.Raw)
            //    {
            //        return currentRawResult;
            //    }
            //    else if (mode == ResultModeEnum.Currency)
            //    {
            //        return currency;
            //    }
            //}

            //SystemMonitor.NotImplementedCritical("Mode not supported.");
            //return 0;
        }