Пример #1
0
        public void SecurityManagerCanCreate_ConcreteFutures_WithCorrectSubscriptions()
        {
            var identifier         = SecurityIdentifier.GenerateFuture(new DateTime(2020, 12, 15), "ED", Market.USA);
            var symbol             = new Symbol(identifier, "ED", Symbol.Empty);
            var marketHoursDbEntry = _marketHoursDatabase.GetEntry(Market.USA, "ED", SecurityType.Equity, TimeZones.NewYork);
            var symbolProperties   = _symbolPropertiesDatabase.GetSymbolProperties(symbol.ID.Market, "ED", symbol.ID.SecurityType, CashBook.AccountCurrency);

            var subscriptionTypes = new List <Type>()
            {
                typeof(TradeBar), typeof(QuoteBar), typeof(OpenInterest)
            };

            var subscriptions = SecurityManager.CreateSecurity(subscriptionTypes,
                                                               _securityPortfolioManager,
                                                               _subscriptionManager,
                                                               marketHoursDbEntry.ExchangeHours,
                                                               marketHoursDbEntry.DataTimeZone,
                                                               symbolProperties,
                                                               _securityInitializer,
                                                               symbol,
                                                               Resolution.Second,
                                                               false,
                                                               1.0m,
                                                               false,
                                                               false,
                                                               false,
                                                               false);

            Assert.IsFalse(symbol.IsCanonical());

            Assert.AreEqual(subscriptions.Subscriptions.Count(), 3);
            Assert.IsTrue(subscriptions.Subscriptions.Any(x => x.TickType == TickType.OpenInterest && x.Type == typeof(OpenInterest)));
            Assert.IsTrue(subscriptions.Subscriptions.Any(x => x.TickType == TickType.Quote && x.Type == typeof(QuoteBar)));
            Assert.IsTrue(subscriptions.Subscriptions.Any(x => x.TickType == TickType.Trade && x.Type == typeof(TradeBar)));
        }
Пример #2
0
        private Subscription CreateSubscription(Resolution resolution, string symbol = "AAPL", bool isInternalFeed = false,
                                                SecurityType type = SecurityType.Equity, TickType tickType         = TickType.Trade)
        {
            var      start = DateTime.UtcNow;
            var      end   = start.AddSeconds(10);
            Security security;
            Symbol   _symbol;

            if (type == SecurityType.Equity)
            {
                _symbol  = new Symbol(SecurityIdentifier.GenerateEquity(DateTime.Now, symbol, Market.USA), symbol);
                security = new Equity(
                    _symbol,
                    SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc),
                    new Cash(Currencies.USD, 0, 1),
                    SymbolProperties.GetDefault(Currencies.USD),
                    ErrorCurrencyConverter.Instance,
                    RegisteredSecurityDataTypesProvider.Null
                    );
            }
            else if (type == SecurityType.Option)
            {
                _symbol = new Symbol(SecurityIdentifier.GenerateOption(DateTime.Now,
                                                                       SecurityIdentifier.GenerateEquity(DateTime.Now, symbol, Market.USA),
                                                                       Market.USA, 0.0m, OptionRight.Call, OptionStyle.American), symbol);
                security = new Option(
                    _symbol,
                    SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc),
                    new Cash(Currencies.USD, 0, 1),
                    new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)),
                    ErrorCurrencyConverter.Instance,
                    RegisteredSecurityDataTypesProvider.Null
                    );
            }
            else if (type == SecurityType.Future)
            {
                _symbol  = new Symbol(SecurityIdentifier.GenerateFuture(DateTime.Now, symbol, Market.USA), symbol);
                security = new Future(
                    _symbol,
                    SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc),
                    new Cash(Currencies.USD, 0, 1),
                    SymbolProperties.GetDefault(Currencies.USD),
                    ErrorCurrencyConverter.Instance,
                    RegisteredSecurityDataTypesProvider.Null
                    );
            }
            else
            {
                throw new Exception("SecurityType not implemented");
            }
            var config = new SubscriptionDataConfig(typeof(TradeBar), _symbol, resolution, DateTimeZone.Utc, DateTimeZone.Utc, true, false, isInternalFeed, false, tickType);
            var timeZoneOffsetProvider     = new TimeZoneOffsetProvider(DateTimeZone.Utc, start, end);
            var enumerator                 = new EnqueueableEnumerator <BaseData>();
            var subscriptionDataEnumerator = new SubscriptionDataEnumerator(config, security.Exchange.Hours, timeZoneOffsetProvider, enumerator);
            var subscriptionRequest        = new SubscriptionRequest(false, null, security, config, start, end);

            return(new Subscription(subscriptionRequest, subscriptionDataEnumerator, timeZoneOffsetProvider));
        }
Пример #3
0
        /// <summary>
        /// Creates a user defined universe symbol
        /// </summary>
        /// <param name="securityType">The security</param>
        /// <param name="market">The market</param>
        /// <returns>A symbol for user defined universe of the specified security type and market</returns>
        public static Symbol CreateSymbol(SecurityType securityType, string market)
        {
            var ticker = $"qc-universe-userdefined-{market.ToLowerInvariant()}-{securityType}";
            SecurityIdentifier sid;

            switch (securityType)
            {
            case SecurityType.Base:
                sid = SecurityIdentifier.GenerateBase(null, ticker, market);
                break;

            case SecurityType.Equity:
                sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
                break;

            case SecurityType.Option:
                var underlying = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlying, market, 0, 0, 0);
                break;

            case SecurityType.FutureOption:
                var underlyingFuture = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingFuture, market, 0, 0, 0);
                break;

            case SecurityType.IndexOption:
                var underlyingIndex = SecurityIdentifier.GenerateIndex(ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlyingIndex, market, 0, 0, OptionStyle.European);
                break;

            case SecurityType.Forex:
                sid = SecurityIdentifier.GenerateForex(ticker, market);
                break;

            case SecurityType.Cfd:
                sid = SecurityIdentifier.GenerateCfd(ticker, market);
                break;

            case SecurityType.Index:
                sid = SecurityIdentifier.GenerateIndex(ticker, market);
                break;

            case SecurityType.Future:
                sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market);
                break;

            case SecurityType.Crypto:
                sid = SecurityIdentifier.GenerateCrypto(ticker, market);
                break;

            case SecurityType.Commodity:
            default:
                throw new NotImplementedException($"The specified security type is not implemented yet: {securityType}");
            }

            return(new Symbol(sid, ticker));
        }
        /// <summary>
        /// Creates a user defined universe symbol
        /// </summary>
        /// <param name="securityType">The security</param>
        /// <param name="market">The market</param>
        /// <returns>A symbol for user defined universe of the specified security type and market</returns>
        public static Symbol CreateSymbol(SecurityType securityType, string market)
        {
            var ticker = string.Format("qc-universe-userdefined-{0}-{1}", market.ToLower(), securityType);
            SecurityIdentifier sid;

            switch (securityType)
            {
            case SecurityType.Base:
                sid = SecurityIdentifier.GenerateBase(ticker, market);
                break;

            case SecurityType.Equity:
                sid = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
                break;

            case SecurityType.Option:
                var underlying = SecurityIdentifier.GenerateEquity(SecurityIdentifier.DefaultDate, ticker, market);
                sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, underlying, market, 0, 0, 0);
                break;

            case SecurityType.Forex:
                sid = SecurityIdentifier.GenerateForex(ticker, market);
                break;

            case SecurityType.Cfd:
                sid = SecurityIdentifier.GenerateCfd(ticker, market);
                break;

            case SecurityType.Future:
                sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, ticker, market);
                break;

            case SecurityType.Crypto:
                sid = SecurityIdentifier.GenerateCrypto(ticker, market);
                break;

            case SecurityType.Commodity:
            default:
                throw new NotImplementedException("The specified security type is not implemented yet: " + securityType);
            }

            return(new Symbol(sid, ticker));
        }
Пример #5
0
        private static Symbol GetSymbol(MapFile mapFile, string market, SecurityType securityType)
        {
            SecurityIdentifier sid;

            switch (securityType)
            {
            case SecurityType.Equity:
                sid = SecurityIdentifier.GenerateEquity(mapFile.FirstDate, mapFile.FirstTicker, market);
                break;

            case SecurityType.Future:
                sid = SecurityIdentifier.GenerateFuture(SecurityIdentifier.DefaultDate, mapFile.Permtick, market);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(securityType), securityType, null);
            }
            return(new Symbol(sid, mapFile.Permtick));
        }
Пример #6
0
        public void CanCreate_ConcreteFutures_WithCorrectSubscriptions()
        {
            var identifier = SecurityIdentifier.GenerateFuture(new DateTime(2020, 12, 15), "ED", Market.CME);
            var symbol     = new Symbol(identifier, "ED", Symbol.Empty);

            var subscriptionTypes = new List <Tuple <Type, TickType> >
            {
                new Tuple <Type, TickType>(typeof(TradeBar), TickType.Trade),
                new Tuple <Type, TickType>(typeof(QuoteBar), TickType.Quote),
                new Tuple <Type, TickType>(typeof(OpenInterest), TickType.OpenInterest)
            };

            var configs  = _subscriptionManager.SubscriptionDataConfigService.Add(symbol, Resolution.Second, false, false, false, false, false, subscriptionTypes);
            var security = _securityService.CreateSecurity(symbol, configs, 1.0m, false);

            Assert.IsFalse(symbol.IsCanonical());

            Assert.AreEqual(security.Subscriptions.Count(), 3);
            Assert.IsTrue(security.Subscriptions.Any(x => x.TickType == TickType.OpenInterest && x.Type == typeof(OpenInterest)));
            Assert.IsTrue(security.Subscriptions.Any(x => x.TickType == TickType.Quote && x.Type == typeof(QuoteBar)));
            Assert.IsTrue(security.Subscriptions.Any(x => x.TickType == TickType.Trade && x.Type == typeof(TradeBar)));
        }