Пример #1
0
        private static SecurityChangedRule CreateSecurityCondition(Security security, IMarketDataProvider provider, Level1Fields field, Unit offset, bool isLess)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            if (offset == null)
            {
                throw new ArgumentNullException(nameof(offset));
            }

            if (offset.Value == 0)
            {
                throw new ArgumentException(LocalizedStrings.Str1051, nameof(offset));
            }

            if (offset.Value < 0)
            {
                throw new ArgumentException(LocalizedStrings.Str1052, nameof(offset));
            }

            var price = (decimal?)provider.GetSecurityValue(security, field);

            if (price == null && offset.Type != UnitTypes.Limit)
            {
                throw new InvalidOperationException(LocalizedStrings.Str1053);
            }

            if (isLess)
            {
                var finishPrice = (decimal)(offset.Type == UnitTypes.Limit ? offset : price - offset);
                return(new SecurityChangedRule(security, provider, s =>
                {
                    var quote = (decimal?)provider.GetSecurityValue(s, field);
                    return quote != null && quote < finishPrice;
                }));
            }
            else
            {
                var finishPrice = (decimal)(offset.Type == UnitTypes.Limit ? offset : price + offset);
                return(new SecurityChangedRule(security, provider, s =>
                {
                    var quote = (decimal?)provider.GetSecurityValue(s, field);
                    return quote != null && quote > finishPrice;
                }));
            }
        }
Пример #2
0
        private static SecurityLastTradeRule CreateLastTradeCondition(Security security, IMarketDataProvider provider, Unit offset, bool isLess)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (offset == null)
            {
                throw new ArgumentNullException(nameof(offset));
            }

            if (offset.Value == 0)
            {
                throw new ArgumentException(LocalizedStrings.Str1051, nameof(offset));
            }

            if (offset.Value < 0)
            {
                throw new ArgumentException(LocalizedStrings.Str1052, nameof(offset));
            }

            var price = (decimal?)provider.GetSecurityValue(security, Level1Fields.LastTradePrice);

            if (price == null && offset.Type != UnitTypes.Limit)
            {
                throw new ArgumentException(LocalizedStrings.Str1054, nameof(security));
            }

            if (isLess)
            {
                var finishPrice = (decimal)(offset.Type == UnitTypes.Limit ? offset : price - offset);
                return(new SecurityLastTradeRule(security, provider, s => (decimal?)provider.GetSecurityValue(s, Level1Fields.LastTradePrice) < finishPrice));
            }
            else
            {
                var finishPrice = (decimal)(offset.Type == UnitTypes.Limit ? offset : price + offset);
                return(new SecurityLastTradeRule(security, provider, s => (decimal?)provider.GetSecurityValue(s, Level1Fields.LastTradePrice) > finishPrice));
            }
        }