public void PythonGetCustomData_Iterate() { using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from AlgorithmImports import * def Test(slice): data = slice.Get(UnlinkedData) count = 0 for singleData in data: count += 1 if count != 2: raise Exception('Unexpected value')").GetAttr("Test"); var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now, Value = 10 }; var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11 }; var slice = new Slice(DateTime.Now, new[] { unlinkedDataSpy, unlinkedDataAapl }); Assert.DoesNotThrow(() => test(new PythonSlice(slice))); } }
public void PythonGetTradeBar() { using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from AlgorithmImports import * def Test(slice): data = slice.Get(TradeBar) return data").GetAttr("Test"); var TradeBarSpy = new TradeBar { Symbol = Symbols.SPY, Time = DateTime.Now, Value = 8 }; var TradeBarAapl = new TradeBar { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 9 }; var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now, Value = 10 }; var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11 }; var slice = new Slice(DateTime.Now, new BaseData[] { unlinkedDataSpy, TradeBarAapl, unlinkedDataAapl, TradeBarSpy }); var data = test(new PythonSlice(slice)); Assert.AreEqual(2, (int)data.Count); Assert.AreEqual(8, (int)data[Symbols.SPY].Value); Assert.AreEqual(9, (int)data[Symbols.AAPL].Value); } }
public void PythonGetAndSymbolTradeBar() { using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from AlgorithmImports import * from QuantConnect.Tests import * def Test(slice): data = slice.Get(TradeBar, Symbols.AAPL) value = data.Value if value != 9: raise Exception('Unexpected value')").GetAttr("Test"); var TradeBarSpy = new TradeBar { Symbol = Symbols.SPY, Time = DateTime.Now, Value = 8 }; var TradeBarAapl = new TradeBar { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 9 }; var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now, Value = 10 }; var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11 }; var slice = new Slice(DateTime.Now, new BaseData[] { unlinkedDataSpy, TradeBarAapl, unlinkedDataAapl, TradeBarSpy }); Assert.DoesNotThrow(() => test(new PythonSlice(slice))); } }
public void AccessesByDataType() { var now = DateTime.UtcNow; var tradeBar = new TradeBar { Symbol = Symbols.SPY, Time = now }; var unlinkedData = new UnlinkedData { Symbol = Symbols.SPY, Time = now }; var quoteBar = new QuoteBar { Symbol = Symbols.SPY, Time = now }; var tick = new Tick(now, Symbols.SPY, 1.1m, 2.1m) { TickType = TickType.Trade }; var openInterest = new OpenInterest(now, Symbols.SPY, 1); var split = new Split(Symbols.SPY, now, 1, 1, SplitType.SplitOccurred); var delisting = new Delisting(Symbols.SPY, now, 1, DelistingType.Delisted); var slice = new Slice(now, new BaseData[] { quoteBar, tradeBar, unlinkedData, tick, split, delisting, openInterest }); Assert.AreEqual(slice.Get(typeof(TradeBar))[Symbols.SPY], tradeBar); Assert.AreEqual(slice.Get(typeof(UnlinkedData))[Symbols.SPY], unlinkedData); Assert.AreEqual(slice.Get(typeof(QuoteBar))[Symbols.SPY], quoteBar); Assert.AreEqual(slice.Get(typeof(Tick))[Symbols.SPY], tick); Assert.AreEqual(slice.Get(typeof(Split))[Symbols.SPY], split); Assert.AreEqual(slice.Get(typeof(Delisting))[Symbols.SPY], delisting); Assert.AreEqual(slice.Get(typeof(OpenInterest))[Symbols.SPY], openInterest); }
public void PythonGetBySymbolCustomData() { using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from AlgorithmImports import * from QuantConnect.Tests import * def Test(slice): data = slice.Get(UnlinkedData) value = data[Symbols.AAPL].Value if value != 11: raise Exception('Unexpected value')").GetAttr("Test"); var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now, Value = 10 }; var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11 }; var slice = new Slice(DateTime.Now, new[] { unlinkedDataSpy, unlinkedDataAapl }); Assert.DoesNotThrow(() => test(new PythonSlice(slice))); } }
public void AccessesGenericallyByTypeAndSymbol() { var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now }; var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now }; var slice = new Slice(DateTime.Now, new[] { unlinkedDataSpy, unlinkedDataAapl }); var unlinkedData = slice.Get<UnlinkedData>(Symbols.SPY); Assert.AreEqual(unlinkedDataSpy, unlinkedData); }
public void AccessesCustomGenericallyByType() { var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now }; var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now }; var slice = new Slice(DateTime.Now, new[] { unlinkedDataSpy, unlinkedDataAapl }); var unlinkedData = slice.Get<UnlinkedData>(); Assert.AreEqual(2, unlinkedData.Count); }
public void AccessesCustomGenericallyByTypeOtherTypesPresent() { var tradeBar = new TradeBar { Symbol = Symbols.SPY, Time = DateTime.Now }; var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.Now }; var slice = new Slice(DateTime.Now, new BaseData[] { unlinkedDataSpy, tradeBar }); var unlinkedData = slice.Get<UnlinkedData>(); Assert.AreEqual(1, unlinkedData.Count); }
public void PythonGetPythonCustomData() { using (Py.GIL()) { dynamic testModule = PythonEngine.ModuleFromString("testModule", @" from AlgorithmImports import * class CustomDataTest(PythonData): def Reader(self, config, line, date, isLiveMode): result = CustomDataTest() result.Symbol = config.Symbol result.Value = 10 return result def GetSource(config, date, isLiveMode): return None class CustomDataTest2(PythonData): def Reader(self, config, line, date, isLiveMode): result = CustomDataTest2() result.Symbol = config.Symbol result.Value = 11 return result def GetSource(config, date, isLiveMode): return None def Test(slice): data = slice.Get(CustomDataTest) return data"); var test = testModule.GetAttr("Test"); var type = Extensions.CreateType(testModule.GetAttr("CustomDataTest")); var customDataTest = new PythonData(testModule.GetAttr("CustomDataTest")()); var config = new SubscriptionDataConfig(type, Symbols.SPY, Resolution.Daily, DateTimeZone.Utc, DateTimeZone.Utc, false, false, false, isCustom: true); var data1 = customDataTest.Reader(config, "something", DateTime.UtcNow, false); var customDataTest2 = new PythonData(testModule.GetAttr("CustomDataTest2")()); var config2 = new SubscriptionDataConfig(config, Extensions.CreateType(testModule.GetAttr("CustomDataTest2"))); var data2 = customDataTest2.Reader(config2, "something2", DateTime.UtcNow, false); var unlinkedDataSpy = new UnlinkedData { Symbol = Symbols.SPY, Time = DateTime.UtcNow, Value = 10 }; var slice = new Slice(DateTime.UtcNow, new[] { unlinkedDataSpy, data2, data1 }); var data = test(new PythonSlice(slice)); Assert.AreEqual(1, (int)data.Count); Assert.AreEqual(10, (int)data[Symbols.SPY].Value); } }
public void PythonEnumerationWorks() { using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from AlgorithmImports import * def Test(slice): for dataPoint in slice: return dataPoint").GetAttr("Test"); var unlinkedDataAapl = new UnlinkedData { Symbol = Symbols.AAPL, Time = DateTime.Now, Value = 11 }; var slice = new Slice(DateTime.Now, new[] { unlinkedDataAapl }); var data = test(new PythonSlice(slice)) as PyObject; var keyValuePair = data.As<KeyValuePair<Symbol, BaseData>>(); Assert.IsNotNull(keyValuePair); Assert.AreEqual(11, keyValuePair.Value.Value); } }