示例#1
0
        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));
            }
        }
示例#2
0
        [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));
            }
        }
示例#3
0
        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);
        }
示例#4
0
        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]);
        }
示例#5
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);
        }
示例#6
0
        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));
            }
        }