Beispiel #1
0
        public void PythonGetCustomData_Iterate_Tiingo()
        {
            using (Py.GIL())
            {
                dynamic test = PythonEngine.ModuleFromString("testModule",
                                                             @"
from clr import AddReference
AddReference(""QuantConnect.Common"")
from QuantConnect import *
from QuantConnect.Data.Custom.Tiingo import TiingoNews
from QuantConnect.Logging import *

def Test(slice):
    data = slice.Get(TiingoNews)
    count = 0
    for singleData in data:
        Log.Trace(str(singleData))
        count += 1
    if count != 2:
        raise Exception('Unexpected value')").GetAttr("Test");
                var quandlSpy = new TiingoNews {
                    Symbol = Symbols.SPY, Time = DateTime.Now, Value = 10
                };
                var tradeBarAapl = new TradeBar {
                    Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 9
                };
                var quandlAapl = new TiingoNews {
                    Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11
                };
                var slice = new Slice(DateTime.Now, new BaseData[] { quandlSpy, tradeBarAapl, quandlAapl });

                Assert.DoesNotThrow(() => test(new PythonSlice(slice)));
            }
        }
Beispiel #2
0
        public void TiingoNewsRoundTrip()
        {
            var symbol = Symbol.CreateBase(
                typeof(TiingoNews),
                Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
                Market.USA);

            var news = new TiingoNews
            {
                ArticleID     = "1000",
                CrawlDate     = DateTime.UtcNow.AddDays(-1),
                DataType      = MarketDataType.Base,
                Description   = "Round trip to planet Protobuf is successful, ushering us into a new era for mining",
                PublishedDate = DateTime.UtcNow.Date,
                Source        = "News Corp.",
                Symbols       = new List <Symbol>
                {
                    Symbol.Create("GOOG", SecurityType.Equity, Market.USA),
                    Symbol.Create("CBS", SecurityType.Equity, Market.USA),
                    Symbol.Create("GLD", SecurityType.Equity, Market.USA)
                },
                Tags = new List <string>
                {
                    "mining",
                    "space",
                    "aero-space",
                    "technology"
                },
                Title = "Round Trip To Planet Protobuf Successful",
                Url   = "https://tiingo.com",

                Time   = DateTime.UtcNow,
                Symbol = symbol
            };

            var serializedNews = news.ProtobufSerialize();

            using (var stream = new MemoryStream(serializedNews))
            {
                var result = (TiingoNews)Serializer.Deserialize <IEnumerable <BaseData> >(stream).First();
                Assert.AreEqual(news.ArticleID, result.ArticleID);
                Assert.AreEqual(news.CrawlDate, result.CrawlDate);
                Assert.AreEqual(news.DataType, result.DataType);
                Assert.AreEqual(news.Description, result.Description);
                Assert.AreEqual(news.PublishedDate, result.PublishedDate);
                Assert.AreEqual(news.Source, result.Source);
                Assert.IsTrue(news.Symbols.SequenceEqual(result.Symbols));
                Assert.IsTrue(news.Tags.SequenceEqual(result.Tags));
                Assert.AreEqual(news.Title, result.Title);
                Assert.AreEqual(news.Url, result.Url);
                Assert.AreEqual(news.Time, result.Time);
                Assert.AreEqual(news.EndTime, result.EndTime);
            }
        }
Beispiel #3
0
        private Slice GetSlice()
        {
            SymbolCache.Clear();
            var quandlSpy = new TiingoNews {
                Symbol = Symbols.SPY, Time = DateTime.Now, Value = 10
            };
            var tradeBarAapl = new TradeBar {
                Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 9
            };
            var quandlAapl = new TiingoNews {
                Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11
            };

            return(new Slice(DateTime.Now, new BaseData[] { quandlSpy, tradeBarAapl, quandlAapl }));
        }
        public void SerializeRoundTrip()
        {
            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };

            var crawlDate        = new DateTime(2020, 3, 19, 10, 0, 0);
            var underlyingSymbol = Symbols.AAPL;
            var symbol           = Symbol.CreateBase(typeof(TiingoNews), underlyingSymbol, QuantConnect.Market.USA);
            var symbolList       = new List <Symbol> {
                underlyingSymbol
            };
            var tags = new List <string> {
                "Stock", "Technology"
            };

            var item = new TiingoNews
            {
                ArticleID = "123456",
                Symbol    = symbol,
                Symbols   = symbolList,
                Tags      = tags,
                Title     = "title",
                CrawlDate = crawlDate,
                Time      = crawlDate
            };

            var serialized   = JsonConvert.SerializeObject(item, settings);
            var deserialized = JsonConvert.DeserializeObject <TiingoNews>(serialized, settings);

            Assert.AreEqual("123456", deserialized.ArticleID);
            Assert.AreEqual(symbol, deserialized.Symbol);
            Assert.AreEqual(symbolList, deserialized.Symbols);
            Assert.AreEqual(tags, deserialized.Tags);
            Assert.AreEqual("title", deserialized.Title);
            Assert.AreEqual(crawlDate, deserialized.CrawlDate);
            Assert.AreEqual(crawlDate, deserialized.Time);
            Assert.AreEqual(crawlDate, deserialized.EndTime);
        }