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++; } } }
public async Task Handle(BagAndDustEvent @event) { var balanceInformation = await _binanceService.GetBalance(); foreach (var walletBalance in balanceInformation.WalletBalances) { if (walletBalance.Currency == Constants.BTC) { if (_config.LowBtcNotification.HasValue) { if (walletBalance.BtcAmount <= _config.LowBtcNotification.Value) { await SendBtcLowNotification(walletBalance.BtcAmount); } } } if (walletBalance.Currency != Constants.BTC && walletBalance.Currency != "USDT" && walletBalance.Currency != "USD") { var averagePrice = await _databaseService.GetBuyAveragePrice(_generalConfig.TradingCurrency, walletBalance.Currency, Constants.Binance, walletBalance.Available); var currentPrice = await _binanceService.GetPrice(_generalConfig.TradingCurrency, walletBalance.Currency); if (_config.BagNotification.HasValue) { await BagManagement(currentPrice, averagePrice, walletBalance); } if (_config.DustNotification.HasValue) { await DustManagement(walletBalance); } } } }
public async Task <decimal> GetPrice(string baseCcy, string termsCurrency, string exchange) { decimal price = 0; switch (exchange) { case Constants.Bittrex: price = await _bittrexService.GetPrice(baseCcy, termsCurrency); break; case Constants.Poloniex: price = await _poloniexService.GetPrice(baseCcy, termsCurrency); break; case Constants.Binance: price = await _binanceService.GetPrice(baseCcy, termsCurrency); break; } return(price); }