public void Py_Get_TradeBarArray() { var securityData = new DynamicSecurityData(RegisteredSecurityDataTypesProvider.Null); var data = new [] { new TradeBar(DateTime.UtcNow, Symbols.SPY, 10m, 20m, 5m, 15m, 10000) }; securityData.StoreData(typeof(TradeBar), data); using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from clr import AddReference AddReference(""QuantConnect.Common"") from QuantConnect import * from QuantConnect.Data.Market import * def Test(dynamicData): data = dynamicData.Get(TradeBar) if data.Low != 5: raise Exception('Unexpected value')").GetAttr("Test"); Assert.DoesNotThrow(() => test(securityData)); } }
[Test] public void Py_StoreData_GetAll_UsesTypeName() { var data = new DynamicSecurityData(RegisteredSecurityDataTypesProvider.Null); data.StoreData(typeof(int), new[] { 1 }); using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from clr import AddReference AddReference(""QuantConnect.Common"") AddReference(""System"") from System import * from QuantConnect import * def Test(dynamicData): data = dynamicData.GetAll(Int32) if len(data) != 1: raise Exception('Unexpected length') if data[0] != 1: raise Exception('Unexpected value')").GetAttr("Test"); Assert.DoesNotThrow(() => test(data)); } }
public void Get_UsesTypeName_AsKey_And_ReturnsLastItem() { var data = new DynamicSecurityData(RegisteredSecurityDataTypesProvider.Null); data.StoreData(typeof(int), new[] { 1, 2, 3 }); var item = data.Get <int>(); Assert.AreEqual(3, item); }
public void StoreData_UsesTypeName_AsKey() { var data = new DynamicSecurityData(RegisteredSecurityDataTypesProvider.Null); data.StoreData(typeof(int), new[] { 1 }); Assert.IsTrue(data.HasProperty(typeof(int).Name)); var arr = (IReadOnlyList <int>)data.GetProperty(typeof(int).Name); Assert.AreEqual(1, arr.Count); Assert.AreEqual(1, arr[0]); }
public void AccessesDataDynamically() { var securityData = new DynamicSecurityData(RegisteredSecurityDataTypesProvider.Null); var data = new List <TradeBar> { new TradeBar(DateTime.UtcNow, Symbols.SPY, 10m, 20m, 5m, 15m, 10000) }; securityData.StoreData(typeof(TradeBar), data); dynamic dynamicSecurityData = securityData; var tradeBars = dynamicSecurityData.TradeBar; Assert.IsInstanceOf <IReadOnlyList <TradeBar> >(tradeBars); }
public void Py_StoreData_HasProperty() { var data = new DynamicSecurityData(RegisteredSecurityDataTypesProvider.Null); data.StoreData(typeof(int), new[] { 1 }); using (Py.GIL()) { dynamic test = PythonEngine.ModuleFromString("testModule", @" from clr import AddReference AddReference(""QuantConnect.Common"") AddReference(""System"") from System import * from QuantConnect import * def Test(dynamicData): data = dynamicData.HasProperty(""Int32"") if not data: raise Exception('Unexpected HasProperty result')").GetAttr("Test"); Assert.DoesNotThrow(() => test(data)); } }