/// <summary>
        /// Open the BacktestLoader Form:
        /// </summary>
        public static void ShowLoadBacktest()
        {
            FormLoadBacktest loadBacktest = new FormLoadBacktest();

            loadBacktest.StartPosition = FormStartPosition.CenterScreen;
            loadBacktest.Show();
        }
        /// <summary>
        /// Launch a backtest.
        /// </summary>
        public void Backtest(bool retry = false)
        {
            
            int _projectID = QuantConnectPlugin.ProjectID;

            if (QuantConnectPlugin.LocalCompile())
            {
                progressBar.Value = 33;
                if(!retry)
                {
                    labelMessage.Text = "Building on QuantConnect...";
                }                

                // Compile on QC
                Async.Add(new APIJob(APICommand.Compile, (compile, errors) =>
                {
                    // Handle login and API errors:
                    switch (QuantConnectPlugin.HandleErrors(errors))
                    {
                        // Handle project specific actions with a login error:
                        case APIErrors.NotLoggedIn:
                            this.SafeInvoke(d => d.ShowLogin(() => { FormLoadBacktest form = new FormLoadBacktest(); form.StartPosition = FormStartPosition.CenterScreen; form.Show(); }));
                            this.SafeInvoke(d => d.Close());
                            return;
                        case APIErrors.CompileTimeout:
                            labelMessage.SafeInvoke(d => d.Text = "Building timedout, retrying...");
                            this.SafeInvoke(d => d.Backtest(true));
                            return;
                        case APIErrors.CompileError:
                            MessageBox.Show("There was a build error: " + errors[0], "QuantConnect Build Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.SafeInvoke(d => d.Close());
                            return;
                    }
                    progressBar.SafeInvoke(d => d.Value = 66);                    
                    labelMessage.SafeInvoke(d => d.Text = "Issuing Backtest...");

                    var packet = (PacketCompile)compile;
                    if (!packet.Success)
                    {
                        pictureError.SafeInvoke(d => d.Visible = true);
                        labelMessage.SafeInvoke(d=>d.Text = "QuantConnect build failed. Please see project at QuantConnect.com");
                        return;
                    }

                    //Sending Backtest...
                    var backtestId = QuantConnectPlugin.GetBacktestID(packet, _projectID);
                    if (backtestId == "")
                    {
                        return;
                    }

                    //Got Id, Open Backtest Form:
                    progressBar.SafeInvoke(d => d.Value = 99);
                    labelMessage.SafeInvoke(d => d.Text = "Backtest Sent Successfully.");
                    pictureCheck.SafeInvoke(d => d.Visible = true);
                    this.SafeInvoke(d => d.LoadResult = backtestId);
                }, _projectID));
            }
            else
            {
                pictureError.Visible = true;
                labelMessage.Text = "Local build failed. Please see Visual Studio";
            }
        }
示例#3
0
        /// <summary>
        /// Launch a backtest.
        /// </summary>
        public void Backtest(bool retry = false)
        {
            int _projectID = QuantConnectPlugin.ProjectID;

            if (QuantConnectPlugin.LocalCompile())
            {
                progressBar.Value = 33;
                if (!retry)
                {
                    labelMessage.Text = "Building on QuantConnect...";
                }

                // Compile on QC
                Async.Add(new APIJob(APICommand.Compile, (compile, errors) =>
                {
                    // Handle login and API errors:
                    switch (QuantConnectPlugin.HandleErrors(errors))
                    {
                    // Handle project specific actions with a login error:
                    case APIErrors.NotLoggedIn:
                        this.SafeInvoke(d => d.ShowLogin(() => { FormLoadBacktest form = new FormLoadBacktest(); form.StartPosition = FormStartPosition.CenterScreen; form.Show(); }));
                        this.SafeInvoke(d => d.Close());
                        return;

                    case APIErrors.CompileTimeout:
                        labelMessage.SafeInvoke(d => d.Text = "Building timedout, retrying...");
                        this.SafeInvoke(d => d.Backtest(true));
                        return;

                    case APIErrors.CompileError:
                        MessageBox.Show("There was a build error: " + errors[0], "QuantConnect Build Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.SafeInvoke(d => d.Close());
                        return;
                    }
                    progressBar.SafeInvoke(d => d.Value = 66);
                    labelMessage.SafeInvoke(d => d.Text = "Issuing Backtest...");

                    var packet = (PacketCompile)compile;
                    if (!packet.Success)
                    {
                        pictureError.SafeInvoke(d => d.Visible = true);
                        labelMessage.SafeInvoke(d => d.Text    = "QuantConnect build failed. Please see project at QuantConnect.com");
                        return;
                    }

                    //Sending Backtest...
                    var backtestId = QuantConnectPlugin.GetBacktestID(packet, _projectID);
                    if (backtestId == "")
                    {
                        return;
                    }

                    //Got Id, Open Backtest Form:
                    progressBar.SafeInvoke(d => d.Value    = 99);
                    labelMessage.SafeInvoke(d => d.Text    = "Backtest Sent Successfully.");
                    pictureCheck.SafeInvoke(d => d.Visible = true);
                    this.SafeInvoke(d => d.LoadResult      = backtestId);
                }, _projectID));
            }
            else
            {
                pictureError.Visible = true;
                labelMessage.Text    = "Local build failed. Please see Visual Studio";
            }
        }
 /// <summary>
 /// Open the BacktestLoader Form:
 /// </summary>
 public static void ShowLoadBacktest()
 {
     FormLoadBacktest loadBacktest = new FormLoadBacktest();
     loadBacktest.StartPosition = FormStartPosition.CenterScreen;
     loadBacktest.Show();
 }