Ejemplo n.º 1
0
        public void NewFeeModelModel_GetOrderFee_Py()
        {
            using (Py.GIL())
            {
                var module = PyModule.FromString(Guid.NewGuid().ToString(),
                                                 "from AlgorithmImports import *\n" +
                                                 "class CustomFeeModel(FeeModel):\n" +
                                                 "   def __init__(self):\n" +
                                                 "       self.CalledGetOrderFee = False\n" +
                                                 "   def GetOrderFee(self, parameters):\n" +
                                                 "       self.CalledGetOrderFee = True\n" +
                                                 "       return OrderFee(CashAmount(15, \"USD\"))");

                var customFeeModel = module.GetAttr("CustomFeeModel").Invoke();
                var wrapper        = new FeeModelPythonWrapper(customFeeModel);

                var result = wrapper.GetOrderFee(new OrderFeeParameters(
                                                     _security,
                                                     new MarketOrder(_security.Symbol, 1, orderDateTime)
                                                     ));

                bool called;
                customFeeModel.GetAttr("CalledGetOrderFee").TryConvert(out called);
                Assert.True(called);
                Assert.IsNotNull(result);
                Assert.AreEqual(15, result.Value.Amount);
                Assert.AreEqual(Currencies.USD, result.Value.Currency);
            }
        }
        public void OldFeeModelModel_GetOrderFee_Py()
        {
            using (Py.GIL())
            {
                var module = PythonEngine.ModuleFromString(Guid.NewGuid().ToString(),
                                                           "from clr import AddReference\n" +
                                                           "AddReference(\"QuantConnect.Common\")\n" +
                                                           "class CustomFeeModel:\n" +
                                                           "   def __init__(self):\n" +
                                                           "       self.CalledGetOrderFee = False\n" +
                                                           "   def GetOrderFee(self, security, order):\n" +
                                                           "       self.CalledGetOrderFee = True\n" +
                                                           "       return 15");

                var customFeeModel = module.GetAttr("CustomFeeModel").Invoke();
                var wrapper        = new FeeModelPythonWrapper(customFeeModel);

                var result = wrapper.GetOrderFee(new OrderFeeParameters(
                                                     _security,
                                                     new MarketOrder(_security.Symbol, 1, orderDateTime)
                                                     ));

                bool called;
                customFeeModel.GetAttr("CalledGetOrderFee").TryConvert(out called);
                Assert.True(called);
                Assert.IsNotNull(result);
                Assert.AreEqual(15, result.Value.Amount);
                Assert.AreEqual(Currencies.USD, result.Value.Currency);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets the fee model
 /// </summary>
 /// <param name="feelModel">Model that represents a fee model</param>
 public void SetFeeModel(PyObject feelModel)
 {
     FeeModel = new FeeModelPythonWrapper(feelModel);
 }