public async Task CreateBots_Enable_WillEnableBots()
        {
            // Arrange
            var exchange      = BuildExchangeWith5Pairs();
            var xCommasClient = BuildXCommasClientWith1ExistingAnd1Blacklisted();
            var request       = GetDefaultRequest();

            var target = new BotManager(NullLogger.Instance, xCommasClient.Object, exchange.Object);

            // Act
            await target.CreateBots(5, true, request, CancellationToken.None);

            // Assert
            xCommasClient.Verify(x => x.EnableBotAsync(It.IsAny <int>()), Times.Exactly(5));
        }
        public async Task CreateBots_CreateMoreBotsThanPairsAvailable_5BotsCreated()
        {
            // Arrange
            var exchange      = BuildExchangeWith5Pairs();
            var xCommasClient = BuildXCommasClientWith1ExistingAnd1Blacklisted();
            var request       = GetDefaultRequest();

            var target = new BotManager(NullLogger.Instance, xCommasClient.Object, exchange.Object);

            // Act
            await target.CreateBots(10, false, request, CancellationToken.None);

            // Assert
            xCommasClient.Verify(x => x.CreateBotAsync(It.IsAny <int>(), request.Strategy, It.IsAny <BotData>()), Times.Exactly(5));
        }
        public async Task CreateBots_NoBuyOrderWanted_WillNotPlaceBuyOrder()
        {
            // Arrange
            var exchange      = BuildExchangeWith5Pairs();
            var xCommasClient = BuildXCommasClientWith1ExistingAnd1Blacklisted();
            var request       = GetDefaultRequest();

            var target = new BotManager(NullLogger.Instance, xCommasClient.Object, exchange.Object);

            // Act
            await target.CreateBots(5, false, request, CancellationToken.None);

            // Assert
            exchange.Verify(x => x.PlaceOrder(It.IsAny <Pair>(), It.IsAny <decimal>()), Times.Never);
        }
        public async Task CreateBots_BuyOrderWanted_WillPlaceBuyOrder()
        {
            // Arrange
            var exchange      = BuildExchangeWith5Pairs();
            var xCommasClient = BuildXCommasClientWith1ExistingAnd1Blacklisted();
            var request       = GetDefaultRequest();

            request.BuyBaseCurrency   = true;
            request.BaseCurrencyToBuy = (decimal)123.45;

            var target = new BotManager(NullLogger.Instance, xCommasClient.Object, exchange.Object);

            // Act
            await target.CreateBots(5, false, request, CancellationToken.None);

            // Assert
            exchange.Verify(x => x.PlaceOrder(It.IsAny <Pair>(), (decimal)123.45), Times.Exactly(5));
        }
        public async Task CreateBots_CheckForExistingBotsAndBlacklistedPairsAndBaseStablecoins_2BotsCreated()
        {
            // Arrange
            var exchange      = BuildExchangeWith5Pairs();
            var xCommasClient = BuildXCommasClientWith1ExistingAnd1Blacklisted();
            var request       = GetDefaultRequest();

            request.SkipExistingPairs    = true;
            request.SkipBlacklistedPairs = true;
            request.SkipBaseStablecoin   = true;

            var target = new BotManager(NullLogger.Instance, xCommasClient.Object, exchange.Object);

            // Act
            await target.CreateBots(5, false, request, CancellationToken.None);

            // Assert
            xCommasClient.Verify(x => x.CreateBotAsync(It.IsAny <int>(), request.Strategy, It.IsAny <BotData>()), Times.Exactly(2));
        }
        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);
                    }
                }
            }
        }