public async Task SellAsync(CandleModel candle) { if (candle != null) { if (_userBalanceService.HasOpenOrder) { await _exchangeProvider.CancelOrderAsync(_tradingPair, _userBalanceService.OpenOrderNumber); return; } var sellPrice = !_userBalanceService.EnableRealtimeTrading ? candle.ClosePrice : _exchangeProvider.GetTicker(_tradingPair).Result.HighestBid; _userBalanceService.TradingCount++; long orderNumber = 0; if (_userBalanceService.EnableRealtimeTrading) { orderNumber = await _exchangeProvider.CreateOrderAsync(TradeType.Sell, _tradingPair, sellPrice, _userBalanceService.Rate); _userBalanceService.HasOpenOrder = true; await CheckOrderInvoked(orderNumber, TradeType.Sell); } var profit = _userBalanceService.GetProfit(sellPrice, candle.StartDateTime); var msg = $"Sell crypto currency. Date: {candle.StartDateTime}; Price: ${sellPrice}; Rate: {_userBalanceService.Rate}; OrderNumber: {orderNumber}\n" + $"Profit: ${profit.Profit}\n" + $"Trading time in hours: {Math.Round(profit.TradingTimeInMinutes / 60.0, 2)}\n" + "\n" + _userBalanceService.TradingSummary(); Console.WriteLine(msg); _emailService.SendEmail(string.Format(_cryptoTradingOptions.EmailSubject, _tradingPair), msg); } }
public Task SellAsync(CandleModel candle) { _hasOpenPosition = false; _userBalanceService.TradingCount++; var profit = _userBalanceService.GetProfit(candle.ClosePrice, candle.StartDateTime); var msg = $"Sell crypto currency. Date: {candle.StartDateTime}; Price: ${candle.ClosePrice}; Rate: {_userBalanceService.Rate}\n" + $"Profit: ${profit.Profit}\n" + $"Trading time in hours: {Math.Round(profit.TradingTimeInMinutes / 60.0, 2)}\n"; Console.WriteLine(msg); return(Task.FromResult(0)); }