Exemplo n.º 1
0
        private void SendForBacktestingCallback(object sender, EventArgs e)
        {
            ExecuteOnProject(sender, async(selectedProjectId, selectedProjectName, files) =>
            {
                var uploadResult = await System.Threading.Tasks.Task.Run(() =>
                                                                         UploadFilesToServer(selectedProjectId, files));
                if (!uploadResult)
                {
                    return;
                }

                var compilationResult = await System.Threading.Tasks.Task.Run(() =>
                                                                              CompileProjectOnServer(selectedProjectId));
                if (!compilationResult.Item1)
                {
                    var errorDialog = new ErrorDialog("Compilation Error", compilationResult.Item2);
                    VsUtils.DisplayDialogWindow(errorDialog);
                    return;
                }

                var backtestResult = await System.Threading.Tasks.Task.Run(() =>
                                                                           BacktestProjectOnServer(selectedProjectId, compilationResult.Item2));
                if (!backtestResult.Item1)
                {
                    var errorDialog = new ErrorDialog("Backtest Failed", backtestResult.Item2);
                    VsUtils.DisplayDialogWindow(errorDialog);
                    return;
                }

                var projectUrl = string.Format(
                    CultureInfo.CurrentCulture,
                    "https://www.quantconnect.com/terminal/#open/{0}",
                    selectedProjectId
                    );
                Process.Start(projectUrl);
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Backtests specific projectId and compileId at QuantConnect
        /// </summary>
        /// <param name="projectId">Target project Id</param>
        /// <param name="compileId">Target compile Id</param>
        /// <returns>Tuple&lt;bool, string&gt;. Item1 is true if backtest succeeded.
        /// Item2 is error message if backtest failed.</returns>
        private async Task <Tuple <bool, string> > BacktestProjectOnServer(int projectId, string compileId)
        {
            VsUtils.DisplayInStatusBar(_serviceProvider, "Backtesting project...");
            var api            = AuthorizationManager.GetInstance().GetApi();
            var backtestName   = BacktestNameProvider.GetNewName();
            var backtestStatus = await System.Threading.Tasks.Task.Run(() => api.CreateBacktest(projectId, compileId, backtestName));

            var backtestId = backtestStatus.BacktestId;

            // Notify observer new backtest
            _backtestObserver.BacktestCreated(projectId, backtestStatus);

            var errorPresent = false;

            while (backtestStatus.Progress < 1 && !errorPresent)
            {
                backtestStatus = await System.Threading.Tasks.Task.Delay(4000).
                                 ContinueWith(_ => api.ReadBacktest(projectId, backtestId));

                errorPresent = !string.IsNullOrEmpty(backtestStatus.Error) ||
                               !string.IsNullOrEmpty(backtestStatus.StackTrace);
                // Notify observer backtest status
                _backtestObserver.BacktestStatusUpdated(projectId, backtestStatus);
            }

            // Notify observer backtest finished
            _backtestObserver.BacktestFinished(projectId, backtestStatus);
            if (errorPresent)
            {
                VsUtils.DisplayInStatusBar(_serviceProvider, "Error when backtesting project");
                return(new Tuple <bool, string>(false, backtestStatus.Error));
            }
            var successMessage = "Backtest completed successfully";

            VsUtils.DisplayInStatusBar(_serviceProvider, successMessage);
            return(new Tuple <bool, string>(true, successMessage));
        }
Exemplo n.º 3
0
        private void SendForBacktestingCallback(object sender, EventArgs e)
        {
            ExecuteOnProject(sender, (selectedProjectId, selectedProjectName, files) =>
            {
                VsUtils.DisplayInStatusBar(_serviceProvider, "Uploading files to server ...");
                UploadFilesToServer(selectedProjectId, files);

                VsUtils.DisplayInStatusBar(_serviceProvider, "Compiling project ...");
                var compileStatus = CompileProjectOnServer(selectedProjectId);
                if (compileStatus.State == Api.CompileState.BuildError)
                {
                    VsUtils.DisplayInStatusBar(_serviceProvider, "Compile error.");
                    VsUtils.ShowMessageBox(_serviceProvider, "Compile Error", "Error when compiling project.");
                    return;
                }

                VsUtils.DisplayInStatusBar(_serviceProvider, "Backtesting project ...");
                Api.Backtest backtest = BacktestProjectOnServer(selectedProjectId, compileStatus.CompileId);
                // Errors are not being transfered in response, so client can't tell if the backtest failed or not.
                // This response error handling code will not work but should.

                /* if (backtest.Errors.Count != 0) {
                 *  VsUtils.DisplayInStatusBar(_serviceProvider, "Backtest error.");
                 *  showMessageBox("Backtest Error", "Error when backtesting project.");
                 *  return;
                 * }*/

                VsUtils.DisplayInStatusBar(_serviceProvider, "Backtest complete.");
                var projectUrl = string.Format(
                    CultureInfo.CurrentCulture,
                    "https://www.quantconnect.com/terminal/#open/{0}",
                    selectedProjectId
                    );
                Process.Start(projectUrl);
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Compiles specific projectId at QuantConnect
        /// </summary>
        /// <param name="projectId">Target project Id</param>
        /// <returns>Tuple&lt;bool, string&gt;. Item1 is true if compilation succeeded.
        /// Item2 is compile Id if compilation succeeded else error message.</returns>
        private Tuple <bool, string> CompileProjectOnServer(int projectId)
        {
            VsUtils.DisplayInStatusBar(_serviceProvider, "Compiling project...");
            var api           = AuthorizationManager.GetInstance().GetApi();
            var compileStatus = api.CreateCompile(projectId);
            var compileId     = compileStatus.CompileId;

            while (compileStatus.State == Api.CompileState.InQueue)
            {
                Thread.Sleep(2000);
                compileStatus = api.ReadCompile(projectId, compileId);
            }

            if (compileStatus.State == Api.CompileState.BuildError)
            {
                // Default to show Errors, now it is coming empty so use Logs. Will only show First Error || Log
                var error = compileStatus.Errors.Count == 0 ?
                            compileStatus.Logs.FirstOrDefault() : compileStatus.Errors.FirstOrDefault();
                VsUtils.DisplayInStatusBar(_serviceProvider, "Error when compiling project");
                return(new Tuple <bool, string>(false, error));
            }
            VsUtils.DisplayInStatusBar(_serviceProvider, "Compilation completed successfully");
            return(new Tuple <bool, string>(true, compileStatus.CompileId));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Log out QuantConnect API
 /// </summary>
 /// <param name="serviceProvider">Visual Studio service provider</param>
 public void Logout(IServiceProvider serviceProvider)
 {
     AuthorizationManager.GetInstance().Logout();
     VsUtils.DisplayInStatusBar(serviceProvider, "Logged out of QuantConnect");
 }
Exemplo n.º 6
0
 protected override void OnClosed(EventArgs e)
 {
     VsUtils.DisplayInStatusBar(_serviceProvider, "Login cancelled");
 }
Exemplo n.º 7
0
 /// <summary>
 /// Log out QuantConnect API
 /// </summary>
 /// <param name="serviceProvider">Visual Studio service provider</param>
 public void DoLogOut(IServiceProvider serviceProvider)
 {
     _credentialsManager.ForgetCredentials();
     AuthorizationManager.GetInstance().LogOut();
     VsUtils.DisplayInStatusBar(serviceProvider, "Logged out of QuantConnect");
 }