public async Task StopAllBots()
        {
            var botMgr = new XCommasLayer(_keys, _logger);

            await ExecuteBulkOperation($"Do you really want to stop {tableControl.Items.Count} Bots?", "Bots are now being stopped", tableControl.Items, async botVm =>
            {
                var res = await botMgr.Disable(botVm.Id, botVm.XCommasAccountId);
                if (res.IsSuccess)
                {
                    _logger.LogInformation($"Bot {botVm.Id} stopped");
                }
                else
                {
                    _logger.LogError($"Could not stop Bot {botVm.Id}. Reason: {res.Error}");
                }
            });
        }
        public async void btnEdit_Click(object sender, EventArgs e)
        {
            var bots = GetSelectedBots(tableControl.SelectedIds);

            if (IsValid(bots))
            {
                var        dlg      = new EditBotDialog.EditBotDialog(bots.Count, new XCommasLayer(_keys, _logger));
                EditBotDto editData = new EditBotDto();
                dlg.EditDto = editData;
                var dr = dlg.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    var botMgr = new XCommasLayer(_keys, _logger);
                    await ExecuteBulkOperation("Applying new settings", bots, async botVm =>
                    {
                        if (editData.IsEnabled.HasValue)
                        {
                            if (editData.IsEnabled.Value)
                            {
                                await botMgr.Enable(botVm.Id, botVm.XCommasAccountId);
                            }
                            else
                            {
                                await botMgr.Disable(botVm.Id, botVm.XCommasAccountId);
                            }
                        }

                        var bot        = await botMgr.GetBotById(botVm.Id, botVm.XCommasAccountId);
                        var updateData = new BotUpdateData(bot);

                        string[] pairs = bot.Pairs;
                        if (!string.IsNullOrWhiteSpace(editData.Pair))
                        {
                            pairs            = new[] { editData.Pair };
                            updateData.Pairs = pairs;
                        }
                        if (!string.IsNullOrWhiteSpace(editData.Name))
                        {
                            updateData.Name = XCommasLayer.GenerateNewName(editData.Name, bot.Strategy.ToString(), pairs, bot.AccountName);
                        }
                        if (editData.MaxActiveDeals.HasValue)
                        {
                            updateData.MaxActiveDeals = editData.MaxActiveDeals.Value;
                        }
                        if (editData.ActiveSafetyOrdersCount.HasValue)
                        {
                            updateData.ActiveSafetyOrdersCount = editData.ActiveSafetyOrdersCount.Value;
                        }
                        if (editData.BaseOrderVolume.HasValue)
                        {
                            updateData.BaseOrderVolume = editData.BaseOrderVolume.Value;
                        }
                        if (editData.Cooldown.HasValue)
                        {
                            updateData.Cooldown = editData.Cooldown.Value;
                        }
                        if (editData.MartingaleStepCoefficient.HasValue)
                        {
                            updateData.MartingaleStepCoefficient = editData.MartingaleStepCoefficient.Value;
                        }
                        if (editData.MartingaleVolumeCoefficient.HasValue)
                        {
                            updateData.MartingaleVolumeCoefficient = editData.MartingaleVolumeCoefficient.Value;
                        }
                        if (editData.MaxSafetyOrders.HasValue)
                        {
                            updateData.MaxSafetyOrders = editData.MaxSafetyOrders.Value;
                        }
                        if (editData.SafetyOrderStepPercentage.HasValue)
                        {
                            updateData.SafetyOrderStepPercentage = editData.SafetyOrderStepPercentage.Value;
                        }
                        if (editData.ProfitCurrency.HasValue)
                        {
                            updateData.ProfitCurrency = editData.ProfitCurrency.Value;
                        }
                        if (editData.StartOrderType.HasValue)
                        {
                            updateData.StartOrderType = editData.StartOrderType.Value;
                        }
                        if (editData.SafetyOrderVolume.HasValue)
                        {
                            updateData.SafetyOrderVolume = editData.SafetyOrderVolume.Value;
                        }
                        if (editData.TakeProfit.HasValue)
                        {
                            updateData.TakeProfit = editData.TakeProfit.Value;
                        }
                        if (editData.TakeProfitType.HasValue)
                        {
                            updateData.TakeProfitType = editData.TakeProfitType.Value;
                        }
                        if (editData.TrailingDeviation.HasValue)
                        {
                            updateData.TrailingDeviation = editData.TrailingDeviation.Value;
                        }
                        if (editData.TrailingEnabled.HasValue)
                        {
                            updateData.TrailingEnabled = editData.TrailingEnabled.Value;
                        }
                        if (editData.BaseOrderVolumeType.HasValue)
                        {
                            updateData.BaseOrderVolumeType = editData.BaseOrderVolumeType.Value;
                        }
                        if (editData.SafetyOrderVolumeType.HasValue)
                        {
                            updateData.SafetyOrderVolumeType = editData.SafetyOrderVolumeType.Value;
                        }
                        if (editData.StopLossPercentage.HasValue)
                        {
                            updateData.StopLossPercentage = editData.StopLossPercentage.Value;
                        }
                        if (editData.StopLossType.HasValue)
                        {
                            updateData.StopLossType = editData.StopLossType.Value;
                        }
                        if (editData.StopLossTimeoutEnabled.HasValue)
                        {
                            updateData.StopLossTimeoutEnabled = editData.StopLossTimeoutEnabled.Value;
                        }
                        if (editData.StopLossTimeout.HasValue)
                        {
                            updateData.StopLossTimeoutInSeconds = editData.StopLossTimeout.Value;
                        }
                        if (editData.LeverageType.HasValue)
                        {
                            updateData.LeverageType = editData.LeverageType.Value;
                        }
                        if (editData.LeverageCustomValue.HasValue)
                        {
                            updateData.LeverageCustomValue = editData.LeverageCustomValue.Value;
                        }

                        if (editData.DisableAfterDealsCountInfo != null)
                        {
                            if (editData.DisableAfterDealsCountInfo.Enable)
                            {
                                updateData.DisableAfterDealsCount = editData.DisableAfterDealsCountInfo.Value;
                            }
                            else
                            {
                                updateData.DisableAfterDealsCount = null;
                            }
                        }

                        if (editData.DealStartConditions.Any())
                        {
                            updateData.Strategies.Clear();
                            updateData.Strategies.AddRange(editData.DealStartConditions);
                        }

                        var res = await botMgr.SaveBot(botVm.Id, updateData, botVm.XCommasAccountId);
                        if (res.IsSuccess)
                        {
                            _logger.LogInformation($"Bot {botVm.Id} updated");
                        }
                        else
                        {
                            _logger.LogError($"Could not update Bot {botVm.Id}. Reason: {res.Error}");
                        }
                    });
                }
            }
        }