Esempio n. 1
0
        /// <summary>
        /// To calculate trade profitability. If the trade was already processed earlier, previous information returns.
        /// </summary>
        /// <param name="trade">Trade.</param>
        /// <param name="info">Information on new trade.</param>
        /// <returns><see langword="true" />, if new trade received, otherwise, <see langword="false" />.</returns>
        public bool ProcessMyTrade(ExecutionMessage trade, out PnLInfo info)
        {
            if (trade == null)
            {
                throw new ArgumentNullException(nameof(trade));
            }

            info = null;

            var tradeId       = trade.TradeId;
            var tradeStringId = trade.TradeStringId;

            if (tradeId != null)
            {
                if (_tradeByIdInfos.TryGetValue(tradeId.Value, out info))
                {
                    return(false);
                }

                var queue = _securityPnLs.SafeAdd(trade.SecurityId, security => new PnLQueue(security));

                info = queue.Process(trade);

                _tradeByIdInfos.Add(tradeId.Value, info);
                _realizedPnL += info.PnL;
                return(true);
            }
            else if (!tradeStringId.IsEmpty())
            {
                if (_tradeByStringIdInfos.TryGetValue(tradeStringId, out info))
                {
                    return(false);
                }

                var queue = _securityPnLs.SafeAdd(trade.SecurityId, security => new PnLQueue(security));

                info = queue.Process(trade);

                _tradeByStringIdInfos.Add(tradeStringId, info);
                _realizedPnL += info.PnL;
                return(true);
            }

            return(false);
        }
		/// <summary>
		/// To calculate trade profitability. If the trade was already processed earlier, previous information returns.
		/// </summary>
		/// <param name="trade">Trade.</param>
		/// <param name="info">Information on new trade.</param>
		/// <returns><see langword="true" />, if new trade received, otherwise, <see langword="false" />.</returns>
		public bool ProcessMyTrade(ExecutionMessage trade, out PnLInfo info)
		{
			if (trade == null)
				throw new ArgumentNullException(nameof(trade));

			var tradeId = trade.GetTradeId();

			if (_tradeInfos.TryGetValue(tradeId, out info))
				return false;

			var queue = _securityPnLs.SafeAdd(trade.SecurityId, security => new PnLQueue(security));

			info = queue.Process(trade);

			_tradeInfos.Add(tradeId, info);
			_realizedPnL += info.PnL;

			return true;
		}
Esempio n. 3
0
        /// <summary>
        /// Рассчитать прибыльность сделки. Если сделка уже ранее была обработана, то возвращается предыдущая информация.
        /// </summary>
        /// <param name="trade">Сделка.</param>
        /// <param name="info">Информация о новой сделке.</param>
        /// <returns><see langword="true"/>, если получена новая сделка, иначе, <see langword="false"/>.</returns>
        public bool ProcessMyTrade(ExecutionMessage trade, out PnLInfo info)
        {
            if (trade == null)
            {
                throw new ArgumentNullException("trade");
            }

            if (_tradeInfos.TryGetValue(trade.TradeId, out info))
            {
                return(false);
            }

            var queue = _securityPnLs.SafeAdd(trade.SecurityId, security => new PnLQueue(security));

            info = queue.Process(trade);

            _tradeInfos.Add(trade.TradeId, info);
            _realizedPnL += info.PnL;

            return(true);
        }