Пример #1
0
        /// <summary>
        /// Calculate order result.
        /// </summary>
        public double GetResult(ResultModeEnum mode)
        {
            lock (this)
            {
                if (this.IsOpen)
                {
                    // Update result.
                    //_currentResult =
                    //    GetRawResultAtPrice(_session.DataProvider.Ask,
                    //    _session.DataProvider.Bid, mode != ResultModeEnum.Pips);
                    //_orderMaximumResultAchieved = Math.Max(_orderMaximumResultAchieved, _currentResult);
                }

                if (mode == ResultModeEnum.Pips)
                {
                    return(_currentResult * Math.Pow(10, _session.SessionInfo.PointDigits));
                }

                if (mode == ResultModeEnum.Raw)
                {
                    return(_currentResult);
                }
                else if (mode == ResultModeEnum.Currency)
                {
                    //return _session.OrderExecutionProvider.Account.CompensateLotSize(_currentResult * _session.SessionInfo.LotSize);
                }

                //SystemMonitor.Throw("Unhandled mode.");
                return(0);
            }
        }
Пример #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));
        }
Пример #3
0
        /// <summary>
        /// Static helper.
        /// </summary>
        public static decimal?GetResult(ResultModeEnum mode, decimal?open, decimal?close, decimal volume, Symbol orderSymbol,
                                        OrderStateEnum state, OrderTypeEnum type, CurrencyConversionManager convertor, Symbol accountCurrency,
                                        decimal lotSize, int decimalPlaces, decimal?ask, decimal?bid)
        {
            if (/*ask.HasValue == false || bid.HasValue == false */
                string.IsNullOrEmpty(orderSymbol.Name))
            {
                return(null);
            }

            Decimal?currentRawResult = null;

            if (state == OrderStateEnum.Executed)
            {
                // Update result.
                currentRawResult = GetRawResult(open, volume, state, type, ask, bid, null, mode != ResultModeEnum.Pips);
            }
            else if (state == OrderStateEnum.Closed)
            {
                currentRawResult = GetRawResult(open, volume, state, type, null, null, close.Value, mode != ResultModeEnum.Pips);
            }

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

            if (mode == ResultModeEnum.Pips)
            {
                //if (state == OrderStateEnum.Closed)
                //{// When closed we need to compensate the
                //    if (OrderInfo.TypeIsBuy(type))
                //    {
                //        return (close - open) * (decimal)Math.Pow(10, decimalPlaces);
                //    }
                //    else
                //    {
                //        return (open - close) * (decimal)Math.Pow(10, decimalPlaces);
                //    }
                //}
                //else
                //{
                return(currentRawResult * (decimal)Math.Pow(10, decimalPlaces));
                //}
            }
            else if (mode == ResultModeEnum.Raw)
            {
                return(currentRawResult);
            }
            else if (mode == ResultModeEnum.Currency)
            {
                return(currentRawResult);
            }
            else if (mode == ResultModeEnum.AccountBaseCurrency)
            {
                if (string.IsNullOrEmpty(accountCurrency.Name) || convertor == null)
                {
                    SystemMonitor.Warning("Mode requires the Account Currency and Convertion Manager to be specified.");
                    return(null);
                }

                if (orderSymbol.IsForexPair)
                {// We have a forex pair and need to rebase to account base currency.
                    double?conversionRate = convertor.GetRate(orderSymbol.ForexCurrency2, accountCurrency.Name, TimeSpan.FromSeconds(1.5), true);
                    if (conversionRate.HasValue == false)
                    {
                        SystemMonitor.OperationError("Failed to establish conversion rate between [" + orderSymbol.ForexCurrency2 + "] and [" + accountCurrency.Name + "].");
                        return(null);
                    }
                }
                else
                {// All other symbols are by default in account base currency prices.
                    return(currentRawResult.Value);
                }
            }

            SystemMonitor.NotImplementedCritical("Mode not supported.");
            return(0);
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 public abstract Decimal?GetResult(ResultModeEnum mode);
Пример #5
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;
        }
Пример #6
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);
        }
Пример #7
0
        /// <summary>
        /// Static helper.
        /// </summary>
        public static decimal? GetResult(ResultModeEnum mode, decimal? open, decimal? close, decimal volume, Symbol orderSymbol,
            OrderStateEnum state, OrderTypeEnum type, CurrencyConversionManager convertor, Symbol accountCurrency, 
            decimal lotSize, int decimalPlaces, decimal? ask, decimal? bid)
        {
            if (/*ask.HasValue == false || bid.HasValue == false */
                string.IsNullOrEmpty(orderSymbol.Name))
            {
                return null;
            }

            Decimal? currentRawResult = null;
            if (state == OrderStateEnum.Executed)
            {
                // Update result.
                currentRawResult = GetRawResult(open, volume, state, type, ask, bid, null, mode != ResultModeEnum.Pips);
            }
            else if (state == OrderStateEnum.Closed)
            {
                currentRawResult = GetRawResult(open, volume, state, type, null, null, close.Value, mode != ResultModeEnum.Pips);
            }

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

            if (mode == ResultModeEnum.Pips)
            {
                //if (state == OrderStateEnum.Closed)
                //{// When closed we need to compensate the
                //    if (OrderInfo.TypeIsBuy(type))
                //    {
                //        return (close - open) * (decimal)Math.Pow(10, decimalPlaces);
                //    }
                //    else
                //    {
                //        return (open - close) * (decimal)Math.Pow(10, decimalPlaces);
                //    }
                //}
                //else
                //{
                    return currentRawResult * (decimal)Math.Pow(10, decimalPlaces);
                //}
            }
            else if (mode == ResultModeEnum.Raw)
            {
                return currentRawResult;
            }
            else if (mode == ResultModeEnum.Currency)
            {
                return currentRawResult;
            }
            else if (mode == ResultModeEnum.AccountBaseCurrency)
            {
                if (string.IsNullOrEmpty(accountCurrency.Name) || convertor == null)
                {
                    SystemMonitor.Warning("Mode requires the Account Currency and Convertion Manager to be specified.");
                    return null;
                }

                if (orderSymbol.IsForexPair)
                {// We have a forex pair and need to rebase to account base currency.
                    double? conversionRate = convertor.GetRate(orderSymbol.ForexCurrency2, accountCurrency.Name, TimeSpan.FromSeconds(1.5), true);
                    if (conversionRate.HasValue == false)
                    {
                        SystemMonitor.OperationError("Failed to establish conversion rate between [" + orderSymbol.ForexCurrency2 + "] and [" + accountCurrency.Name + "].");
                        return null;
                    }
                }
                else
                {// All other symbols are by default in account base currency prices.
                    return currentRawResult.Value;
                }
            }

            SystemMonitor.NotImplementedCritical("Mode not supported.");
            return 0;
        }
Пример #8
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;
        }
Пример #9
0
 /// <summary>
 /// 
 /// </summary>
 public abstract Decimal? GetResult(ResultModeEnum mode);