/// <summary>
 /// Set the results:
 /// </summary>
 public void SetBacktestResult(PacketBacktestResult result)
 {
     this._results = result;
     this._backtestResultUpdated = true;
 }
Exemplo n.º 2
0
        public static void Consumer()
        {
            while (true)
            {
                if (Queue.Count > 0)
                {
                    APIJob job;
                    if (Queue.TryDequeue(out job))
                    {
                        switch (job.Command)
                        {
                            case APICommand.Authenticate:
                                bool loggedIn = false;
                                if (job.Parameters.Length == 2)
                                {
                                    loggedIn = QuantConnectPlugin.API.Authenticate((string)job.Parameters[0], (string)job.Parameters[1]);
                                }
                                job.Callback(loggedIn, new List<string>());
                                break;

                            case APICommand.ProjectList:
                                var packet = QuantConnectPlugin.API.ProjectList();
                                List<Project> projectList = new List<Project>();
                                if (packet.Projects != null) projectList = packet.Projects;
                                job.Callback(projectList, packet.Errors);
                                break;

                            case APICommand.NewProject:
                                var projectCreate = QuantConnectPlugin.API.ProjectCreate(job.Parameters[0].ToString());
                                var newProject = 0;
                                if (projectCreate.ProjectId != null) newProject = projectCreate.ProjectId;
                                job.Callback(newProject, projectCreate.Errors);
                                break;

                            case APICommand.OpenProject:
                                var files = new PacketProjectFiles();
                                List<File> projectFiles = new List<File>();
                                if (job.Parameters.Length == 1)
                                {
                                    files = QuantConnectPlugin.API.ProjectFiles((int)job.Parameters[0]);
                                }
                                if (files.Files != null) projectFiles = files.Files;
                                job.Callback(projectFiles, files.Errors);
                                break;

                            case APICommand.CheckQCAlgoVersion:
                                bool latestversion = QuantConnectPlugin.API.CheckQCAlgorithmVersion();
                                job.Callback(latestversion, new List<string>());
                                break;

                            case APICommand.Compile:
                                QuantConnectPlugin.SaveToCloud(false);
                                var compile = new PacketCompile();
                                if (job.Parameters.Length == 1)
                                {
                                    compile = QuantConnectPlugin.API.Compile((int)job.Parameters[0]);
                                }
                                job.Callback(compile, compile.Errors);
                                break;
                            case APICommand.UpdateTemplate:
                                job.Callback(true, new List<string>());
                                break;
                            case APICommand.BacktestResults:
                                var backtestResult = new PacketBacktestResult();
                                if (job.Parameters.Length == 1)
                                {
                                    backtestResult = QuantConnectPlugin.API.BacktestResults((string)job.Parameters[0]);
                                }
                                job.Callback(backtestResult, backtestResult.Errors);
                                break;
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }