コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasketSecurityBaseProcessor{TSecurity}"/>.
        /// </summary>
        /// <param name="basketSecurity">Instruments basket.</param>
        protected BasketSecurityBaseProcessor(TSecurity basketSecurity)
        {
            BasketSecurity = basketSecurity ?? throw new ArgumentNullException(nameof(basketSecurity));

            BasketLegs = BasketSecurity.InnerSecurityIds.ToArray();
            SecurityId = BasketSecurity.ToSecurityId();

            if (BasketLegs.IsEmpty())
            {
                throw new ArgumentException(LocalizedStrings.SecurityDoNotContainsLegs.Put(basketSecurity.Id), nameof(basketSecurity));
            }
        }
コード例 #2
0
        private IEnumerable <Message> ProcessMessage <TMessage>(Dictionary <SecurityId, TMessage> dict, SecurityId securityId, TMessage message, Func <TMessage[], TMessage> convert)
            where TMessage : Message
        {
            dict[securityId] = message.TypedClone();

            if (dict.Count != BasketLegs.Length)
            {
                yield break;
            }

            yield return(convert(BasketLegs.Select(leg => dict[leg]).ToArray()));

            dict.Clear();
        }
コード例 #3
0
        private decimal Calculate(IEnumerable <CandleMessage> candles, bool isPrice, Func <CandleMessage, decimal> getPart)
        {
            var values = candles.Select(getPart).ToArray();

            try
            {
                return(Calculate(values, isPrice));
            }
            catch (ArithmeticException excp)
            {
                throw new ArithmeticException(LocalizedStrings.BuildIndexError.Put(SecurityId, BasketLegs.Zip(values, (s, v) => $"{s}: {v}").JoinCommaSpace()), excp);
            }
        }