Get information from python

Created at 21 Dec 2020, 20:45
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
LE

leonavonm

Joined 16.12.2020

Get information from python
21 Dec 2020, 20:45


Good day!

I am using some ML packages in python to make predictions based on indicator data which should then be used to execute orders in cTrader. I found the following code on the internet, however  am not getting any output from the following program, where cmd is the directory of the python script. The python code is very simple it is just tester code that prints, thus, Print(1). I tried adding the line Console.ReadLine(); which did not help and I tried to write the python output to a new file start.Arguments = string.Format("{0} {1} > output.txt 2>&1", cmd, args); but I could not find the location of the file. Any help would be apprecaited 

private void run_cmd(string cmd, string args)
{
     ProcessStartInfo start = new ProcessStartInfo();
     start.FileName = "my/full/path/to/python.exe";
     start.Arguments = string.Format("{0} {1}", cmd, args);
     start.UseShellExecute = false;
     start.RedirectStandardOutput = true;
     using(Process process = Process.Start(start))
     {
         using(StreamReader reader = process.StandardOutput)
         {
             string result = reader.ReadToEnd();
             Print(result);
         }
     }
}

@leonavonm
Replies

leonavonm
21 Dec 2020, 22:34 ( Updated at: 21 Dec 2020, 22:38 )

RE:Source of problem

leonavonm said:

Good day!

I am using some ML packages in python to make predictions based on indicator data which should then be used to execute orders in cTrader. I found the following code on the internet, however  am not getting any output from the following program, where cmd is the directory of the python script. The python code is very simple it is just tester code that prints, thus, Print(1). I tried adding the line Console.ReadLine(); which did not help and I tried to write the python output to a new file start.Arguments = string.Format("{0} {1} > output.txt 2>&1", cmd, args); but I could not find the location of the file. Any help would be apprecaited 

private void run_cmd(string cmd, string args)
{
     ProcessStartInfo start = new ProcessStartInfo();
     start.FileName = "my/full/path/to/python.exe";
     start.Arguments = string.Format("{0} {1}", cmd, args);
     start.UseShellExecute = false;
     start.RedirectStandardOutput = true;
     using(Process process = Process.Start(start))
     {
         using(StreamReader reader = process.StandardOutput)
         {
             string result = reader.ReadToEnd();
             Print(result);
         }
     }
}

I did try to see where the problem lies and I found that the python script might not be executing correctly since when it is run with the following code the python script is supposed to write to a csv file with some new code but this isn't visible. Thus it is not that data is received and I can't access it, it is the fact that data is never sent, here is the new code I tried to use without solution. 

ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = "Path\\To\\python.exe";
            start.Arguments = "Path\\To\\Thing.py";
            start.UseShellExecute = false;
            start.RedirectStandardOutput = false;
            using (Process process = Process.Start(start))
            {

            }


@leonavonm