private async void btnCopy_Click(object sender, EventArgs e) { var dlg = new CopyBotDialog.CopyBotDialog(_keys, _logger); var dr = dlg.ShowDialog(this); if (dr == DialogResult.OK) { var botMgr = new XCommasLayer(_keys, _logger); await ExecuteBulkOperation($"Copy {tableControl.SelectedIds.Count} Grid Bots in Account '{dlg.Account.Name}' now?", "Grid Bots are now being copied", GetSelectedBots(tableControl.SelectedIds), async botVm => { var botEntity = await botMgr.GetGridBotById(botVm.Id, botVm.XCommasAccountId); botEntity.AccountId = dlg.Account.Id; var res = await botMgr.CreateGridBot(dlg.Account.Id, botEntity, dlg.Account.XCommasAccountId); if (res.IsSuccess) { if (dlg.IsEnabled.HasValue && dlg.IsEnabled.Value || !dlg.IsEnabled.HasValue && botEntity.IsEnabled) { await botMgr.EnableGridBot(res.Data.Id, dlg.Account.XCommasAccountId); } _logger.LogInformation($"Grid Bot {res.Data.Id} created (as a copy of Grid Bot {botVm.Id})"); } else { _logger.LogError($"Could not copy Grid 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 EditGridBotDialog.EditGridBotDialog(bots.Count, new XCommasLayer(_keys, _logger)); EditGridBotDto editData = new EditGridBotDto(); 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.EnableGridBot(botVm.Id, botVm.XCommasAccountId); } else { await botMgr.DisableGridBot(botVm.Id, botVm.XCommasAccountId); } } var botData = await botMgr.GetGridBotById(botVm.Id, botVm.XCommasAccountId); var updateData = new GridBotUpdateData(botVm.Id, botData); if (editData.QuantityPerGrid.HasValue) { updateData.QuantityPerGrid = editData.QuantityPerGrid.Value; } if (editData.UpperLimitPrice.HasValue) { updateData.UpperLimitPrice = editData.UpperLimitPrice.Value; } if (editData.LowerLimitPrice.HasValue) { updateData.LowerLimitPrice = editData.LowerLimitPrice.Value; } if (editData.GridsQuantity.HasValue) { updateData.GridsQuantity = editData.GridsQuantity.Value; } var res = await botMgr.SaveGridBot(botVm.Id, updateData, botVm.XCommasAccountId); if (res.IsSuccess) { _logger.LogInformation($"Grid Bot {botVm.Id} updated"); } else { _logger.LogError($"Could not update Grid Bot {botVm.Id}. Reason: {res.Error}"); } }); } } }