/// <summary> /// Calculates a buy signal based on several technical analysis indicators. /// </summary> /// <param name="market">The market we're going to check against.</param> /// <returns></returns> private async Task <TradeSignal> GetStrategySignal(string market) { try { var minimumDate = _strategy.GetMinimumDateTime(); var candleDate = _strategy.GetCurrentCandleDateTime(); var candles = await _api.GetTickerHistory(market, _strategy.IdealPeriod, minimumDate); // We eliminate all candles that aren't needed for the dataset incl. the last one (if it's the current running candle). candles = candles.Where(x => x.Timestamp >= minimumDate && x.Timestamp < candleDate).ToList(); // Not enough candles to perform what we need to do. if (candles.Count < _strategy.MinimumAmountOfCandles) { _logger.LogWarning("Not enough candle data for {Market}...", market); return(new TradeSignal { TradeAdvice = TradeAdvice.Hold, MarketName = market }); } // Get the date for the last candle. var signalDate = candles[candles.Count - 1].Timestamp; // This is an outdated candle... if (signalDate < _strategy.GetSignalDate()) { _logger.LogInformation("Outdated candle for {Market}...", market); return(null); } // This calculates an advice for the next timestamp. var advice = _strategy.Forecast(candles); return(new TradeSignal { TradeAdvice = advice, MarketName = market, SignalCandle = _strategy.GetSignalCandle(candles) }); } catch (Exception ex) { // Couldn't get a buy signal for this market, no problem. Let's skip it. _logger.LogError(ex, "Couldn't get buy signal for {Market}...", market); return(null); } }
/// <summary> /// Retrieves a trend list for the given market. /// </summary> /// <param name="tradeMarket"></param> /// <returns></returns> private async Task <List <ITradeAdvice> > GetTrend(string tradeMarket) { var minimumDate = DateTime.UtcNow.AddHours(-120); var candles = await _api.GetTickerHistory(tradeMarket, minimumDate, Period.Hour); var signalDate = candles[candles.Count - 1].Timestamp; // This is an outdated candle... if (signalDate < DateTime.UtcNow.AddMinutes(-120)) { return new List <ITradeAdvice>() { } } ; // This calculates a buy signal for each candle. var trend = _strategy.Prepare(candles.Where(x => x.Timestamp > minimumDate).ToList()); return(trend); }
/// <summary> /// Calculates a buy signal based on several technical analysis indicators. /// </summary> /// <param name="market">The market we're going to check against.</param> /// <returns></returns> private async Task <ITradeAdvice> GetStrategySignal(string market) { try { _log($"Checking market {market}..."); var minimumDate = _strategy.GetMinimumDateTime(); var candleDate = _strategy.GetCurrentCandleDateTime(); var candles = await _api.GetTickerHistory(market, minimumDate, _strategy.IdealPeriod); // We eliminate all candles that aren't needed for the dataset incl. the last one (if it's the current running candle). candles = candles.Where(x => x.Timestamp >= minimumDate && x.Timestamp < candleDate).ToList(); // Not enough candles to perform what we need to do. if (candles.Count < _strategy.MinimumAmountOfCandles) { return(new SimpleTradeAdvice(TradeAdvice.Hold)); } // Get the date for the last candle. var signalDate = candles[candles.Count - 1].Timestamp; // This is an outdated candle... if (signalDate < _strategy.GetSignalDate()) { return(null); } // This calculates an advice for the next timestamp. var advice = _strategy.Forecast(candles); return(advice); } catch (Exception) { // Couldn't get a buy signal for this market, no problem. Let's skip it. _log($"Couldn't get buy signal for {market}..."); return(null); } }