/// <summary>
        /// Refresh the data source, polling the API.
        /// </summary>
        private void timerRefresh_Tick(object sender, EventArgs e)
        {
            if (_processing)
            {
                return;
            }
            _processing = true;

            statusLabel.Text = "Updating Results for Backtest Id: " + _backtestId + "...";

            Async.Add(new APIJob(APICommand.BacktestResults, (backtestResult, 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(() => { FormOpenProject form = new FormOpenProject(); form.StartPosition = FormStartPosition.CenterScreen; form.Show(); }));
                    this.SafeInvoke(d => d.Close());
                    return;
                }

                //Handle Results Packet:
                PacketBacktestResult packet = (PacketBacktestResult)backtestResult;

                this.SafeInvoke(d => d.SetBacktestResult(packet));
            }, _backtestId)); // End of Async
        } // End of timer:
Esempio n. 2
0
        private void OpenProjects_Load(object sender, EventArgs e)
        {
            // Load projects
            buttonOpen.Enabled = false;
            this.UseWaitCursor = true;
            List <Project> projectList = new List <Project>();

            try
            {
                Async.Add(new APIJob(APICommand.ProjectList, (projectfiles, 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(() => { FormOpenProject form = new FormOpenProject(); form.StartPosition = FormStartPosition.CenterScreen; form.Show(); }));
                        this.SafeInvoke(d => d.Close());
                        return;
                    }

                    listViewProjects.SafeInvoke(d => d.Items.Clear());
                    listViewProjects.SafeInvoke(d => d.BeginUpdate());

                    foreach (var project in (List <Project>)projectfiles)
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text         = project.Id.ToString();

                        ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem();
                        subitem.Text = project.Name.ToString();
                        item.SubItems.Add(subitem);

                        subitem      = new ListViewItem.ListViewSubItem();
                        subitem.Text = project.Modified.ToString();
                        item.SubItems.Add(subitem);

                        listViewProjects.SafeInvoke(d => d.Items.Add(item));
                    }
                    listViewProjects.SafeInvoke(d => d.EndUpdate());
                    buttonOpen.SafeInvoke(d => d.Enabled = true);
                    this.SafeInvoke(d => d.UseWaitCursor = false);
                    this.SafeInvoke(d => d.SizeLastColumn(listViewProjects));
                }));
            }
            catch
            {
                MessageBox.Show("Connection timeout.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Create a new project.
        /// </summary>
        public void CreateProject(bool retry = false)
        {
            progressBar.Value = 10;
            labelMessage.Text = "Creating Project on QuantConnect...";

            // Create New Project on QC
            Async.Add(new APIJob(APICommand.NewProject, (projectIdObj, 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(() => { FormCreateProject form = new FormCreateProject(); form.StartPosition = FormStartPosition.CenterScreen; form.Show(); }));
                    this.SafeInvoke(d => d.Close());
                    return;
                }

                int projectId = projectIdObj == null ? 0 : Convert.ToInt32(projectIdObj);
                if (projectId == 0)
                {
                    //Show the error form
                    labelMessage.SafeInvoke(d => d.Text    = "Sorry there was an error with your request. ");
                    pictureError.SafeInvoke(d => d.Visible = true);
                }
                else
                {
                    //Else we have a new id, time to load the template:
                    labelMessage.SafeInvoke(d => d.Text = "Project Created, Opening...");
                    progressBar.SafeInvoke(d => d.Value = 90);

                    //Open the project and close the loading dialog.
                    QuantConnectPlugin.OpenProject(projectId, ProjectName, () => {
                        this.SafeInvoke(d => d.Close());
                        QuantConnectPlugin.SetButtonsState(true);
                    });
                }
            }, ProjectName));
        }
Esempio n. 4
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";
            }
        }