示例#1
0
        /// <summary>
        /// Download the file and open a new visual studio solution
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenBtn_Click(object sender, EventArgs e)
        {
            int selectedProject = 0;

            if (listViewProjects.SelectedItems.Count == 0)
            {
                return;
            }

            selectedProject = Convert.ToInt32(listViewProjects.SelectedItems[0].Text);
            projectName     = listViewProjects.FocusedItem.SubItems[1].Text;

            buttonOpen.Enabled = false;
            this.UseWaitCursor = true;

            //Run the function that downloads and handles the projects
            bool success = QuantConnectPlugin.OpenProject(selectedProject, projectName, () => {
                buttonOpen.SafeInvoke((d) => d.Enabled = true);
                this.SafeInvoke((d) => d.UseWaitCursor = false);
                this.SafeInvoke((d) => d.Close());
                QuantConnectPlugin.SetButtonsState(true);
            });

            if (!success)
            {
                buttonOpen.Enabled           = true;
                this.UseWaitCursor           = false;
                QuantConnectPlugin.ProjectID = 0;
            }
        }
        /// <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:
 /// <summary>
 /// Plugin Constructor:
 /// </summary>
 public QCPluginPackage()
 {
     Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
     Commands = new Dictionary <string, MenuCommand>();
     // If the username and password files exist, login:
     QuantConnectPlugin.Initialize();
 }
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // IDE
            ApplicationObject = (DTE2)GetService(typeof(DTE));

            Commands.Clear();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for each menu item.
                CommandID   menuCommandID = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.cmdIdQuantConnect);
                MenuCommand menuItem      = new MenuCommand(MenuItemCallback, menuCommandID);
                mcs.AddCommand(menuItem);

                CommandID setCredentialsID = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.setCredentials);
                Commands.Add("SetCredentials", new MenuCommand(SetCredentialsItemCallback, setCredentialsID));
                mcs.AddCommand(Commands["SetCredentials"]);

                CommandID   newProjectID   = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.newProject);
                MenuCommand newProjectItem = new MenuCommand(NewProjectCallback, newProjectID);
                mcs.AddCommand(newProjectItem);

                CommandID   openProjectID   = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.openProject);
                MenuCommand openProjectItem = new MenuCommand(OpenProjectItemCallback, openProjectID);
                mcs.AddCommand(openProjectItem);

                CommandID backtestID = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.backtest);
                Commands.Add("Backtest", new MenuCommand(BacktestItemCallback, backtestID));
                mcs.AddCommand(Commands["Backtest"]);

                CommandID logoutID = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.logout);
                Commands.Add("Logout", new MenuCommand(LogoutItemCallback, logoutID));
                mcs.AddCommand(Commands["Logout"]);

                CommandID deleteID = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.delete);
                Commands.Add("Delete", new MenuCommand(DeleteItemCallback, deleteID));
                mcs.AddCommand(Commands["Delete"]);

                CommandID saveID = new CommandID(GuidList.guidQCPluginCmdSet, (int)PkgCmdIDList.save);
                Commands.Add("Save", new MenuCommand(SaveItemCallback, saveID));
                mcs.AddCommand(Commands["Save"]);
            }
            QuantConnectPlugin.SetButtonsState(false);
        }
示例#5
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);
            }
        }
示例#6
0
        /// <summary>
        /// Launch the backtest result form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Tick(object sender, EventArgs e)
        {
            if (this.LoadResult != "")
            {
                FormBacktestChart form = new FormBacktestChart();
                form.SetBacktestId(LoadResult);
                form.Show();
                this.Close();
            }

            if (QuantConnectPlugin.RateLimitReached)
            {
                QuantConnectPlugin.RateLimitReached = false;
                QuantConnectPlugin.ShowRateLimit();
                this.Close();
            }
        }
示例#7
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            buttonLogin.Enabled = false;
            this.UseWaitCursor  = true;
            Email    = textBoxEmail.Text;
            Password = textBoxPassword.Text;

            if (checkBoxRememberCredentials.Checked)
            {
                QuantConnectPlugin.SaveCredentials(Email, Password);
            }

            try
            {
                Async.Add(new APIJob(APICommand.Authenticate, (loggedIn, errors) =>
                {
                    buttonLogin.SafeInvoke(d => d.Enabled = true);
                    this.SafeInvoke(d => d.UseWaitCursor  = false);

                    if (!(bool)loggedIn)
                    {
                        MessageBox.Show("Wrong user name or password", "QuantConnect Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        QuantConnectPlugin.Email    = Email;
                        QuantConnectPlugin.Password = Password;
                        this.SafeInvoke(d =>
                        {
                            if (d.SuccessCallback != null)
                            {
                                d.SuccessCallback();
                            }
                        });
                        this.SafeInvoke(d => d.Close());
                    }
                }, Email, Password));
            }
            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));
        }
 /// <summary>
 /// Shwo the new project dialog:
 /// </summary>
 private void NewProjectCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.ShowNewProject();
 }
示例#10
0
 /// <summary>
 /// Logout Menu Option
 /// </summary>
 private void LogoutItemCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.ShowLogout();
 }
示例#11
0
 /// <summary>
 /// Click on Delete Project
 /// </summary>
 private void DeleteItemCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.DeleteProject();
 }
示例#12
0
 /// <summary>
 /// Click on Save Project
 /// </summary>
 private void SaveItemCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.SaveToCloud(true);
 }
示例#13
0
 /// <summary>
 /// Click on Backtest.
 /// </summary>
 private void BacktestItemCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.ShowLoadBacktest();
 }
示例#14
0
 /// <summary>
 /// Click on Set Credentials (Currently hidden).
 /// </summary>
 private void SetCredentialsItemCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.ShowSaveCredentials();
 }
示例#15
0
 public void DeleteSavedCredentials(object sender, EventArgs e)
 {
     QuantConnectPlugin.RemoveCredentials();
     Close();
 }
示例#16
0
 private void SetCredentials_Load(object sender, EventArgs e)
 {
     string[] credentials = QuantConnectPlugin.LoadCredentials();
     textBoxEmail.Text    = Email;
     textBoxPassword.Text = Password;
 }
示例#17
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";
            }
        }
示例#18
0
 /// <summary>
 /// Click on Open Projects
 /// </summary>
 private void OpenProjectItemCallback(object sender, EventArgs e)
 {
     QuantConnectPlugin.ShowProjects();
 }
示例#19
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);
            }
        }