Пример #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));
            }

            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);
        }