예제 #1
0
        public async Task CheckForUpdates(bool isAutomaticUpdateCheck)
        {
            try
            {
                IsUpdateError           = false;
                IsAppUpToDate           = false;
                IsUpdateAvailable       = false;
                IsPresetUpdateAvailable = false;

                BusyContent = _localizationHelper.GetLocalization("UpdatePreferencesBusyCheckUpdates");
                IsBusy      = true;

                await CheckForNewAppVersionAsync();

                await CheckForPresetsAsync(isAutomaticUpdateCheck);

                if (!isAutomaticUpdateCheck)
                {
                    IsAppUpToDate = !IsUpdateAvailable && !IsPresetUpdateAvailable;
                }

                if (isAutomaticUpdateCheck)
                {
                    //If not already prompted
                    if (!_appSettings.PromptedForAutoUpdateCheck)
                    {
                        _appSettings.PromptedForAutoUpdateCheck = true;

                        if (!_messageBoxService.ShowQuestion(Application.Current.MainWindow,
                                                             _localizationHelper.GetLocalization("ContinueCheckingForUpdates"),
                                                             _localizationHelper.GetLocalization("ContinueCheckingForUpdatesTitle")))
                        {
                            AutomaticUpdateCheck = false;
                        }
                    }
                }

                IsBusy = false;
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error checking version.");

                IsUpdateError = true;

                IsBusy = false;

                if (isAutomaticUpdateCheck)
                {
                    _messageBoxService.ShowError(Application.Current.MainWindow,
                                                 _localizationHelper.GetLocalization("VersionCheckErrorMessage"),
                                                 _localizationHelper.GetLocalization("VersionCheckErrorTitle"));
                }
            }
        }
예제 #2
0
 private void ExecuteResetHotkeys(object param)
 {
     if (_messageBoxService.ShowQuestion(_localizationHelper.GetLocalization(RESET_ALL_CONFIRMATION_MESSAGE),
                                         _localizationHelper.GetLocalization(RESET_ALL)))
     {
         HotkeyCommandManager.ResetHotkeys();
     }
 }
예제 #3
0
        public static bool ShowQuestion(this IMessageBoxService service, string message, string title = "Question")
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            return(service.ShowQuestion(null, message, title));
        }
        private async Task ExecuteBulkOperation(string confirmationMessage, string inProgressText, List <BotViewModel> bots, Func <BotViewModel, Task> updateOperation)
        {
            var dr = _mbs.ShowQuestion(confirmationMessage);

            if (dr == DialogResult.Yes)
            {
                await ExecuteBulkOperation(inProgressText, bots, updateOperation).ConfigureAwait(false);
            }
        }
        public async Task OnCreate()
        {
            if (IsValid())
            {
                var dr = _mbs.ShowQuestion($"Do you really want to create {View.NumberOfBotsToCreate} Bots now?");
                if (dr == DialogResult.Yes)
                {
                    View.SetCreateInProgress(true);

                    IExchange exchange = null;
                    if (View.IsBinanceSelected)
                    {
                        exchange = new ExchangeLayer.Implementations.Binance(_keys);
                    }
                    else if (View.IsHuobiSelected)
                    {
                        exchange = new ExchangeLayer.Implementations.Huobi(_keys);
                    }

                    var botMgr = new BotManager(_logger, new XCommasClient(_keys, View.UsePaperTrading), exchange);

                    try
                    {
                        _cancellationTokenSource = new CancellationTokenSource();
                        var cancellationToken = _cancellationTokenSource.Token;
                        await botMgr.CreateBots(View.NumberOfBotsToCreate, View.Enable, _settings, cancellationToken);

                        View.SetCreateInProgress(false);
                        _mbs.ShowInformation("Operation finished! See output section for details.");
                    }
                    catch (Exception exception)
                    {
                        _logger.LogError(exception.Message);
                        _mbs.ShowError("Error: " + exception);
                    }
                    finally
                    {
                        View.SetCreateInProgress(false);
                    }
                }
            }
        }
 private void TargetPersonEditForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!_isUserCanceling)
     {
         if (_isDirty)
         {
             var result = _messageBoxService.ShowQuestion("你编辑了目标库,保存你所做的修改吗?");
             if (result == DialogResult.Yes)
             {
                 DeleteAndCommitChanges();
             }
         }
     }
 }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!HasChanges)
            {
                _mbs.ShowInformation("No changes to save.");
                return;
            }

            if (IsValid())
            {
                var dr = _mbs.ShowQuestion($"Save these settings to {_botCount} bots now?");
                if (dr == DialogResult.Yes)
                {
                    if (chkChangeIsEnabled.Checked)
                    {
                        if (cmbIsEnabled.SelectedItem.ToString() == "Enable")
                        {
                            EditDto.IsEnabled = true;
                        }
                        else if (cmbIsEnabled.SelectedItem.ToString() == "Disable")
                        {
                            EditDto.IsEnabled = false;
                        }
                    }

                    if (chkChangeLowerLimit.Checked)
                    {
                        EditDto.LowerLimitPrice = numLowerLimit.Value;
                    }
                    if (chkChangeUpperLimit.Checked)
                    {
                        EditDto.UpperLimitPrice = numUpperLimit.Value;
                    }
                    if (chkChangeQuantityPerGrid.Checked)
                    {
                        EditDto.QuantityPerGrid = numQuantityPerGrid.Value;
                    }
                    if (chkChangeGridQuantity.Checked)
                    {
                        EditDto.GridsQuantity = Convert.ToInt32(numGridQuantity.Value);
                    }

                    this.DialogResult = DialogResult.OK;
                }
            }
        }
        private async Task ExecuteBulkOperation(string confirmationMessage, string operationName, Func <DealViewModel, Task> updateOperation)
        {
            if (IsValid(tableControl.SelectedIds))
            {
                var dr = _mbs.ShowQuestion(confirmationMessage);
                if (dr == DialogResult.Yes)
                {
                    var cancellationTokenSource = new CancellationTokenSource();
                    var loadingView             = new ProgressView.ProgressView(operationName, cancellationTokenSource, tableControl.SelectedIds.Count);
                    loadingView.Show(this);

                    int i = 0;
                    await tableControl.SelectedItems.ParallelForEachAsync(
                        async deal =>
                    {
                        await updateOperation(deal);
                        i++;
                        loadingView.SetProgress(i);
                    }, 2, cancellationTokenSource.Token).ConfigureAwait(true);

                    loadingView.Close();
                    if (cancellationTokenSource.IsCancellationRequested)
                    {
                        _logger.LogInformation("Operation cancelled");
                        _mbs.ShowError("Operation cancelled!", "");
                    }
                    else
                    {
                        _mbs.ShowInformation($"Operation finished. See output section for details.");
                    }

                    _logger.LogInformation("Refreshing Deals");
                    await tableControl.RefreshData(_keys);
                }
            }
        }
예제 #9
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!HasChanges)
            {
                _mbs.ShowInformation("No changes to save.");
                return;
            }

            if (IsValid())
            {
                var dr = _mbs.ShowQuestion($"Save these settings to {_botCount} bots now?");
                if (dr == DialogResult.Yes)
                {
                    if (chkChangeIsEnabled.Checked)
                    {
                        if (cmbIsEnabled.SelectedItem.ToString() == "Enable")
                        {
                            EditDto.IsEnabled = true;
                        }
                        else if (cmbIsEnabled.SelectedItem.ToString() == "Disable")
                        {
                            EditDto.IsEnabled = false;
                        }
                    }

                    if (chkChangeStartOrderType.Checked)
                    {
                        Enum.TryParse(cmbStartOrderType.SelectedItem.ToString(), out StartOrderType startOrderType);
                        EditDto.StartOrderType = startOrderType;
                    }
                    if (chkChangeBaseOrderSize.Checked)
                    {
                        EditDto.BaseOrderVolume = numBaseOrderVolume.Value;
                    }
                    if (chkChangeName.Checked)
                    {
                        EditDto.Name = txtName.Text;
                    }
                    if (chkChangeSafetyOrderSize.Checked)
                    {
                        EditDto.SafetyOrderVolume = numSafetyOrderVolume.Value;
                    }
                    if (chkChangeTargetProfit.Checked)
                    {
                        EditDto.TakeProfit = numTargetProfit.Value;
                    }
                    if (chkChangeTrailingEnabled.Checked)
                    {
                        EditDto.TrailingEnabled = cmbTtpEnabled.SelectedItem.ToString() == "Enable" ? true : false;
                    }
                    if (chkChangeTrailingDeviation.Checked)
                    {
                        EditDto.TrailingDeviation = numTrailingDeviation.Value;
                    }
                    if (chkChangeMaxSafetyTradesCount.Checked)
                    {
                        EditDto.MaxSafetyOrders = (int)numMaxSafetyTradesCount.Value;
                    }
                    if (chkChangeMaxActiveSafetyTradesCount.Checked)
                    {
                        EditDto.ActiveSafetyOrdersCount = (int)numMaxActiveSafetyTradesCount.Value;
                    }
                    if (chkChangePriceDeviationToOpenSafetyOrders.Checked)
                    {
                        EditDto.SafetyOrderStepPercentage = numPriceDeviationToOpenSafetyOrders.Value;
                    }
                    if (chkChangeSafetyOrderVolumeScale.Checked)
                    {
                        EditDto.MartingaleVolumeCoefficient = numSafetyOrderVolumeScale.Value;
                    }
                    if (chkChangeSafetyOrderStepScale.Checked)
                    {
                        EditDto.MartingaleStepCoefficient = numSafetyOrderStepScale.Value;
                    }
                    if (chkChangeCooldownBetweenDeals.Checked)
                    {
                        EditDto.Cooldown = (int)numCooldownBetweenDeals.Value;
                    }

                    if (chkDisableAfterDealsCount.Checked)
                    {
                        EditDto.DisableAfterDealsCountInfo = new DisableAfterDealsCountDto();
                        if (cmbDisableAfterDealsCount.SelectedItem.ToString() == "Enable")
                        {
                            EditDto.DisableAfterDealsCountInfo.Enable = true;
                            EditDto.DisableAfterDealsCountInfo.Value  = (int)numDisableAfterDealsCount.Value;
                        }
                    }

                    this.DialogResult = DialogResult.OK;
                }
            }
        }
예제 #10
0
        public async Task OnCopy()
        {
            var ids = View.SelectedBotIds;

            if (IsValid(ids))
            {
                var dlg = new ChooseAccount.ChooseAccount(_keys, _logger);
                var dr  = dlg.ShowDialog(View);
                if (dr == DialogResult.OK)
                {
                    dr = _mbs.ShowQuestion($"Copy {ids.Count} Bots in Account '{dlg.Account.Name}' now?");
                    if (dr == DialogResult.Yes)
                    {
                        var cancellationTokenSource = new CancellationTokenSource();
                        var loadingView             = new ProgressView.ProgressView("Bots are now being copied", cancellationTokenSource, ids.Count);
                        loadingView.Show(View);

                        var botMgr = new BotManager(_keys, _logger);

                        int i = 0;
                        foreach (var botId in ids)
                        {
                            i++;
                            loadingView.SetProgress(i);

                            if (cancellationTokenSource.IsCancellationRequested)
                            {
                                break;
                            }

                            var bot = await botMgr.GetBotById(botId);

                            bot.AccountId = dlg.Account.Id;
                            var res = await botMgr.CreateBot(dlg.Account.Id, bot.Strategy, bot);

                            if (res.IsSuccess)
                            {
                                if (bot.IsEnabled)
                                {
                                    await botMgr.Enable(res.Data.Id);
                                }
                                _logger.LogInformation($"Bot {botId} created");
                            }
                            else
                            {
                                _logger.LogError($"Could not copy Bot {botId}. Reason: {res.Error}");
                            }
                        }

                        loadingView.Close();
                        if (cancellationTokenSource.IsCancellationRequested)
                        {
                            _logger.LogInformation("Operation cancelled");
                            _mbs.ShowError("Operation cancelled!", "");
                        }
                        else
                        {
                            _mbs.ShowInformation("Bulk Copy finished. See output section for details.");
                        }

                        _logger.LogInformation("Refreshing Bots");
                        await RefreshBots();
                    }
                }
            }
        }