private static Symbol CreateSymbol(int x) { return(new Symbol( SecurityIdentifier.GenerateBase(x.ToString(CultureInfo.InvariantCulture), Market.USA), x.ToString(CultureInfo.InvariantCulture) )); }
public void Generates12Character() { var sid1 = SecurityIdentifier.GenerateBase(null, "123456789012", Market.USA); Assert.AreEqual("123456789012", sid1.Symbol); Console.WriteLine(sid1); }
public void Generates12Character() { var sid1 = SecurityIdentifier.GenerateBase(null, "123456789012", Market.USA); Assert.AreEqual("123456789012", sid1.Symbol); Log.Trace(sid1.ToString()); }
/// <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: sid = SecurityIdentifier.GenerateOption(SecurityIdentifier.DefaultDate, ticker, 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.Commodity: case SecurityType.Future: default: throw new NotImplementedException("The specified security type is not implemented yet: " + securityType); } return(new Symbol(sid, ticker)); }
public void SecurityManagerCanCreate_CustomSecurities_WithCorrectSubscriptions() { var equitySymbol = new Symbol(SecurityIdentifier.GenerateBase("BTC", Market.USA), "BTC"); var equityMarketHoursDbEntry = _marketHoursDatabase.GetEntry(Market.USA, "BTC", SecurityType.Base, TimeZones.NewYork); var equitySymbolProperties = _symbolPropertiesDatabase.GetSymbolProperties(equitySymbol.ID.Market, equitySymbol, equitySymbol.ID.SecurityType, CashBook.AccountCurrency); var equity = SecurityManager.CreateSecurity(typeof(Bitcoin), _securityPortfolioManager, _subscriptionManager, equityMarketHoursDbEntry.ExchangeHours, equityMarketHoursDbEntry.DataTimeZone, equitySymbolProperties, _securityInitializer, equitySymbol, Resolution.Second, false, 1.0m, false, false, false, false); Assert.AreEqual(equity.Subscriptions.Count(), 1); Assert.AreEqual(equity.Subscriptions.First().Type, typeof(Bitcoin)); Assert.AreEqual(equity.Subscriptions.First().TickType, TickType.Trade); }
public void GenerateBaseDataWithTickerUsingMapFile() { var expectedFirstDate = new DateTime(1998, 1, 2); var sid = SecurityIdentifier.GenerateBase(null, "TWX", Market.USA, mapSymbol: true); Assert.AreEqual(sid.Date, expectedFirstDate); Assert.AreEqual(sid.Symbol, "AOL"); }
public void GenerateBase_SymbolAppendsDptTypeName_WhenBaseDataTypeIsNotNull() { var symbol = "BTC"; var expected = "BTC.Bitcoin"; var baseDataType = typeof(RabbitMQLive.Bitcoin); var sid = SecurityIdentifier.GenerateBase(baseDataType, symbol, Market.USA); Assert.AreEqual(expected, sid.Symbol); }
/// <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)); }
public void GenerateBase_UsesProvidedSymbol_WhenBaseDataTypeIsNull() { var symbol = "BTC"; var expected = "BTC"; var baseDataType = (Type)null; var sid = SecurityIdentifier.GenerateBase(baseDataType, symbol, Market.USA); Assert.AreEqual(expected, sid.Symbol); }
public void AddContainsAndRemoveWork() { var symbol = new Symbol(SecurityIdentifier.GenerateBase(_symbol, Market.USA), _symbol); var collection = new PortfolioTargetCollection(); var target = new PortfolioTarget(symbol, 1); collection.Add(target); Assert.AreEqual(collection.Count, 1); Assert.IsTrue(collection.Contains(target)); Assert.IsTrue(collection.Remove(target)); Assert.AreEqual(collection.Count, 0); }
public void CanCreate_CustomSecurities_WithCorrectSubscriptions() { var symbol = new Symbol(SecurityIdentifier.GenerateBase("BTC", Market.USA), "BTC"); _marketHoursDatabase.SetEntryAlwaysOpen(Market.USA, "BTC", SecurityType.Base, TimeZones.NewYork); var configs = _subscriptionManager.SubscriptionDataConfigService.Add(typeof(LiveTradingFeaturesAlgorithm.Bitcoin), symbol, Resolution.Second, false, false, false); var security = _securityService.CreateSecurity(symbol, configs, 1.0m, false); Assert.AreEqual(security.Subscriptions.Count(), 1); Assert.AreEqual(security.Subscriptions.First().Type, typeof(LiveTradingFeaturesAlgorithm.Bitcoin)); Assert.AreEqual(security.Subscriptions.First().TickType, TickType.Trade); }
/// <summary> /// AddData a new user defined data source, requiring only the minimum config options. /// </summary> /// <param name="dataType">Data source type</param> /// <param name="symbol">Key/Symbol for data</param> /// <param name="resolution">Resolution of the Data Required</param> /// <param name="timeZone">Specifies the time zone of the raw data</param> /// <param name="fillDataForward">When no data available on a tradebar, return the last data that was generated</param> /// <param name="leverage">Custom leverage per security</param> public void AddData(Type dataType, string symbol, Resolution resolution, DateTimeZone timeZone, bool fillDataForward = false, decimal leverage = 1.0m) { var marketHoursDbEntry = _marketHoursDatabase.GetEntry(Market.USA, symbol, SecurityType.Base, timeZone); //Add this to the data-feed subscriptions var symbolObject = new Symbol(SecurityIdentifier.GenerateBase(symbol, Market.USA), symbol); var symbolProperties = _symbolPropertiesDatabase.GetSymbolProperties(Market.USA, symbol, SecurityType.Base, CashBook.AccountCurrency); //Add this new generic data as a tradeable security: var security = SecurityManager.CreateSecurity(dataType, Portfolio, SubscriptionManager, marketHoursDbEntry.ExchangeHours, marketHoursDbEntry.DataTimeZone, symbolProperties, SecurityInitializer, symbolObject, resolution, fillDataForward, leverage, true, false, true, LiveMode); AddToUserDefinedUniverse(security); }
public void EndTimeShiftedOneDayForward() { var date = new DateTime(2020, 5, 21); var cboe = new QuantConnect.Data.Custom.CBOE.CBOE(); var cboeData = "2020-05-21,1,1,1,1"; var symbol = new Symbol(SecurityIdentifier.GenerateBase(typeof(QuantConnect.Data.Custom.CBOE.CBOE), "VIX", QuantConnect.Market.USA), "VIX"); var actual = cboe.Reader(new SubscriptionDataConfig( typeof(QuantConnect.Data.Custom.CBOE.CBOE), symbol, Resolution.Daily, QuantConnect.TimeZones.Utc, QuantConnect.TimeZones.Utc, false, false, false, true), cboeData, date, false); Assert.AreEqual(date, actual.Time); Assert.AreEqual(date.AddDays(1), actual.EndTime); }
public void FredApiParsesDataCorrectly() { // Arrange var fileInfo = new FileInfo("./TestData/FredVixData.json"); var content = File.ReadAllText(fileInfo.FullName); var sid = SecurityIdentifier.GenerateBase(typeof(BaseData), Fred.CBOE.VIX, QuantConnect.Market.USA, false); var symbol = new Symbol(sid, Fred.CBOE.VIX); var subscriptionDataConfig = new SubscriptionDataConfig(typeof(BaseData), symbol, Resolution.Daily, DateTimeZone.Utc, DateTimeZone.Utc, false, false, false, true); var fredApi = new FredApi(); // Act var data = (BaseDataCollection)fredApi.Reader(subscriptionDataConfig, content, new DateTime(2019, 01, 04), false); // Assert Assert.AreEqual(18, data.Data.Count); Assert.AreEqual(23.22, data.Data.First().Value); Assert.AreEqual(18.87, data.Data.Last().Value); Assert.AreEqual(357.66m, data.Data.Sum(d => d.Value)); }
/// <summary> /// Reads the data, which in this case is fake incremental data /// </summary> /// <param name="config">Subscription configuration</param> /// <param name="line">Line of data</param> /// <param name="date">Date of the request</param> /// <param name="isLiveMode">Is live mode</param> /// <returns>Incremental BaseData instance</returns> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode) { var vix = new CBOE(); _step += 0.10m; var open = _start + _step; var close = _start + _step + 0.02m; var high = close; var low = open; return(new IncrementallyGeneratedCustomData { Open = open, High = high, Low = low, Close = close, Time = date, Symbol = new Symbol( SecurityIdentifier.GenerateBase(typeof(IncrementallyGeneratedCustomData), "VIX", Market.USA, false), "VIX"), Period = vix.Period, DataType = vix.DataType }); }
public void SecurityManagerCanCreate_ConcreteFutures_WithCorrectSubscriptions() { var ed = SecurityIdentifier.GenerateBase("ED", Market.USA); 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))); }
public void DeserializesCorrectly() { var content = @"{ ""id"": 1, ""author"": ""Gerardo"", ""created"": ""2018-01-25T12:00:00Z"", ""updated"": ""2018-01-26T12:00:00Z"", ""title"": ""Unit Test Beats Expectations"", ""teaser"": ""The unit test beat reviewer's expectations, reporters say"", ""body"": ""<p>The unit test beat reviewer's expectations, reporters say - 'This is the best test I've ever seen' says Martin</p>"", ""channels"": [ { ""name"": ""earnings"" } ], ""stocks"": [ { ""name"": ""AAPL"" } ], ""tags"": [ { ""name"": ""unit test"" }, { ""name"": ""testing"" } ] }"; // Put in a single line to avoid potential failure due to platform-specific behavior (\r\n vs. \n) var expectedSerialized = @"{""id"":1,""author"":""Gerardo"",""created"":""2018-01-25T12:00:00Z"",""updated"":""2018-01-26T12:00:00Z"",""title"":""Unit Test Beats Expectations"",""teaser"":""The unit test beat reviewer's expectations, reporters say"",""body"":"" The unit test beat reviewer's expectations, reporters say - 'This is the best test I've ever seen' says Martin "",""channels"":[{""name"":""earnings""}],""stocks"":[{""name"":""AAPL""}],""tags"":[{""name"":""unit test""},{""name"":""testing""}],""EndTime"":""2018-01-26T12:00:00Z"",""DataType"":0,""IsFillForward"":false,""Time"":""2018-01-26T12:00:00Z"",""Symbol"":{""Value"":""AAPL"",""ID"":""AAPL.BenzingaNews R735QTJ8XC9W"",""Permtick"":""AAPL""},""Value"":0.0,""Price"":0.0}"; var expectedSymbol = new Symbol( SecurityIdentifier.GenerateEquity( "AAPL", QuantConnect.Market.USA, true, null, new DateTime(2018, 1, 25) ), "AAPL" ); var expectedBaseSymbol = new Symbol( SecurityIdentifier.GenerateBase( typeof(BenzingaNews), "AAPL", QuantConnect.Market.USA, mapSymbol: true, date: new DateTime(2018, 1, 25) ), "AAPL" ); var result = JsonConvert.DeserializeObject <BenzingaNews>(content, new BenzingaNewsJsonConverter(symbol: expectedBaseSymbol, liveMode: false)); var serializedResult = JsonConvert.SerializeObject(result, Formatting.None, new BenzingaNewsJsonConverter(symbol: expectedBaseSymbol, liveMode: false)); var resultFromSerialized = JsonConvert.DeserializeObject <BenzingaNews>(serializedResult, new BenzingaNewsJsonConverter(symbol: expectedBaseSymbol, liveMode: false)); Assert.AreEqual(expectedSerialized, serializedResult); Assert.AreEqual(1, result.Id); Assert.AreEqual( Parse.DateTimeExact("2018-01-25T12:00:00Z", "yyyy-MM-ddTHH:mm:ssZ", DateTimeStyles.AdjustToUniversal), result.CreatedAt); Assert.AreEqual( Parse.DateTimeExact("2018-01-26T12:00:00Z", "yyyy-MM-ddTHH:mm:ssZ", DateTimeStyles.AdjustToUniversal), result.UpdatedAt); Assert.AreEqual(result.UpdatedAt, result.EndTime); Assert.AreEqual(result.UpdatedAt, result.Time); Assert.AreEqual("Gerardo", result.Author); Assert.AreEqual("Unit Test Beats Expectations", result.Title); Assert.AreEqual("The unit test beat reviewer's expectations, reporters say", result.Teaser); Assert.AreEqual(" The unit test beat reviewer's expectations, reporters say - 'This is the best test I've ever seen' says Martin ", result.Contents); Assert.AreEqual(new List <string> { "earnings" }, result.Categories); Assert.AreEqual(new List <string> { "unit test", "testing" }, result.Tags); Assert.AreEqual(new List <Symbol> { expectedSymbol }, result.Symbols); // Now begin comparing the resultFromSerialized and result instances Assert.AreEqual(result.Id, resultFromSerialized.Id); Assert.AreEqual(result.Author, resultFromSerialized.Author); Assert.AreEqual(result.CreatedAt, resultFromSerialized.CreatedAt); Assert.AreEqual(result.UpdatedAt, resultFromSerialized.UpdatedAt); Assert.AreEqual(result.Title, resultFromSerialized.Title); Assert.AreEqual(result.Teaser, resultFromSerialized.Teaser); Assert.AreEqual(result.Contents, resultFromSerialized.Contents); Assert.AreEqual(result.Categories, resultFromSerialized.Categories); Assert.AreEqual(result.Symbols, resultFromSerialized.Symbols); Assert.AreEqual(result.Tags, resultFromSerialized.Tags); }
private static Symbol CreateSymbol(int x) { return(new Symbol(SecurityIdentifier.GenerateBase(x.ToString(), Market.USA), x.ToString())); }