Esempio n. 1
0
        public async Task Handle(DepositAndWithdrawalEvent @event)
        {
            if (_config.DepositNotification.HasValue && _config.DepositNotification.Value)
            {
                var deposits = await _binanceService.GetNewDeposits();

                var i = 0;
                foreach (var deposit in deposits)
                {
                    if (i > 30)
                    {
                        var message = new StringBuffer();
                        message.Append(StringContants.BinanceMoreThan30Deposits);
                        await _bus.SendAsync(new SendMessageCommand(message));

                        break;
                    }

                    var priceInBtc = await _binanceService.GetPrice(_generalConfig.TradingCurrency, deposit.Currency);

                    var btcAmount = priceInBtc * Convert.ToDecimal(deposit.Amount);
                    await SendDepositNotification(deposit, btcAmount);

                    i++;
                }
            }

            if (_config.WithdrawalNotification.HasValue && _config.WithdrawalNotification.Value)
            {
                var withdrawals = await _binanceService.GetNewWithdrawals();

                var i = 0;
                foreach (var withdrawal in withdrawals)
                {
                    if (i > 3)
                    {
                        var message = new StringBuffer();
                        message.Append(StringContants.BinanceMoreThan30Withdrawals);
                        break;
                    }

                    var priceInBtc = await _binanceService.GetPrice(_generalConfig.TradingCurrency, withdrawal.Currency);

                    var btcAmount = priceInBtc * Convert.ToDecimal(withdrawal.Amount);
                    await SendWithdrawalNotification(withdrawal, btcAmount);

                    i++;
                }
            }
        }