public override void Init()
        {
            barData = this.HistoryDataSeries as BarData;

            HistoricalDataManager.OnLoaded = (data) =>
            {
                if (data.Count > period * 2)
                {
                    for (int i = period * 6; i >= 0; i--)
                    {
                        ohlc.Insert(0, new OHLCV(data as BarData, i));
                    }

                    var methodArguments = new PythonCallerArgs();

                    methodArguments.SetPeriodArg(period);

                    methodArguments.SetArg(ohlc);

                    var pyCaller = new PythonCaller(module_name);

                    Dictionary <string, List <double> > resultJson = pyCaller.CallClassMethod(class_name, def_name, methodArguments);

                    var result = resultJson["result"];

                    result = result.Where(x => !Double.IsNaN(x)).ToList();

                    for (int i = 0; i < result.Count; i++)
                    {
                        Lines[0].SetValue(result[i], i);
                    }
                }
            };
        }
Пример #2
0
        public Dictionary <string, List <double> > CallClassMethod(string className, string method, PythonCallerArgs args)
        {
            results = "";
            errors  = "";
            string argString = args.Serialized();

            //Caller produces the command:
            // path/to/python.exe caller.py path/to/python/module python_module_name class_name method_name args_string
            //caller.py is the aggregator script, which finds the desired script (python_module_name.py), imports its contents and calls the class method
            //args_string is JSON-formatted array of the arguments for the desired script (python_module_name.py)

            psi.Arguments = $"\"{caller}\" \"{scriptPath}\" \"{scriptName}\" \"{className}\" \"{method}\" \"{argString}\"";

            var value     = System.Environment.GetEnvironmentVariable("PATH");
            var new_value = envPath + "\\:" + envPath + "\\Scripts:" + value;

            System.Environment.SetEnvironmentVariable("PATH", new_value);

            using (var process = Process.Start(psi))
            {
                errors  = process.StandardError.ReadToEnd();
                results = process.StandardOutput.ReadToEnd();
            }

            Dictionary <string, List <double> > ob = JsonConvert.DeserializeObject <Dictionary <string, List <double> > >(results);

            return(ob);
        }