Beispiel #1
0
 public ChartService(CandleLoadingService candleLoadingService,
                     IIndicatorComputingService indicatorComputingService,
                     ConfigurationService configurationService)
 {
     _candleLoadingService      = candleLoadingService;
     _indicatorComputingService = indicatorComputingService;
     _configurationService      = configurationService;
 }
 public OpenPositionAnalysisService(CandleLoadingService candleLoadingService,
                                    OrderBookLoadingService orderBookLoadingService,
                                    IIndicatorComputingService indicatorComputingService,
                                    ConfigurationService configurationService)
 {
     _candleLoadingService      = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService));
     _orderBookLoadingService   = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService));
     _indicatorComputingService = indicatorComputingService ?? throw new ArgumentNullException(nameof(indicatorComputingService));
     _configurationService      = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
 }
 public TripleFrameRSIStrategyAnalysisService(CandleLoadingService candleLoadingService,
                                              OrderBookLoadingService orderBookLoadingService,
                                              IIndicatorComputingService indicatorComputingService,
                                              ConfigurationService configurationService)
 {
     CandleLoadingService      = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService));
     OrderBookLoadingService   = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService));
     IndicatorComputingService = indicatorComputingService ?? throw new ArgumentNullException(nameof(indicatorComputingService));
     ConfigurationService      = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
 }
Beispiel #4
0
 public FakeTradingConnector(IRepository <Domain.Core.Entities.Trading.Order> orderRepository,
                             IRepository <Domain.Core.Entities.Trading.TradingBallance> tradingBallanceRepository,
                             CandleLoadingService candleLoadingService,
                             ConfigurationService configurationService)
 {
     _orderRepository           = orderRepository;
     _tradingBallanceRepository = tradingBallanceRepository;
     _candleLoadingService      = candleLoadingService;
     _configurationService      = configurationService;
 }
 public TinkoffTradingAdvisorController(
     IStockSocketConnector stockSocketConnector,
     CandleLoadingService candleLoadingService,
     IMarketNewPositionAnalysisService marketNewPositionAnalysisService,
     ConfigurationService configurationService,
     ILoggingService loggingService)
 {
     _stockSocketConnector             = stockSocketConnector ?? throw new ArgumentNullException(nameof(stockSocketConnector));
     _candleLoadingService             = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService));
     _marketNewPositionAnalysisService = marketNewPositionAnalysisService ?? throw new ArgumentNullException(nameof(marketNewPositionAnalysisService));
     _configurationService             = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
     _loggingService = loggingService ?? throw new ArgumentNullException(nameof(loggingService));
 }
Beispiel #6
0
 public TradingPositionWorker(CandleLoadingService candleLoadingService,
                              OrderBookLoadingService orderBookLoadingService,
                              TradingReportsService tradingReportsService,
                              IMarketPendingPositionAnalysisService marketPendingPositionAnalysisService,
                              IMarketOpenPositionAnalysisService marketOpenPositionAnalysisService,
                              ITradingPositionService tradingPositionService,
                              ConfigurationService configurationService)
 {
     _candleLoadingService    = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService));
     _orderBookLoadingService = orderBookLoadingService ?? throw new ArgumentNullException(nameof(orderBookLoadingService));
     _tradingReportsService   = tradingReportsService ?? throw new ArgumentNullException(nameof(tradingReportsService));
     _marketPendingPositionAnalysisService = marketPendingPositionAnalysisService ?? throw new ArgumentNullException(nameof(marketPendingPositionAnalysisService));
     _marketOpenPositionAnalysisService    = marketOpenPositionAnalysisService ?? throw new ArgumentNullException(nameof(marketOpenPositionAnalysisService));
     _tradingPositionService = tradingPositionService ?? throw new ArgumentNullException(nameof(tradingPositionService));
     _configurationService   = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
 }
Beispiel #7
0
 public SocketTradingController(
     IRepository <Order> orderRepository,
     IStockSocketConnector stockSocketConnector,
     IStockRestConnector stockRestConnector,
     CandleLoadingService candleLoadingService,
     IMarketNewPositionAnalysisService marketNewPositionAnalysisService,
     TradingPositionWorkerFactory tradingPositionWorkerFactory,
     ITradingPositionService tradingPositionService,
     ConfigurationService configurationService,
     TradingEventsObserver tradingEventsObserver,
     ILoggingService loggingService)
 {
     _orderRepository                  = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
     _stockSocketConnector             = stockSocketConnector ?? throw new ArgumentNullException(nameof(stockSocketConnector));
     _stockRestConnector               = stockRestConnector ?? throw new ArgumentNullException(nameof(stockRestConnector));
     _candleLoadingService             = candleLoadingService ?? throw new ArgumentNullException(nameof(candleLoadingService));
     _marketNewPositionAnalysisService = marketNewPositionAnalysisService ?? throw new ArgumentNullException(nameof(marketNewPositionAnalysisService));
     _tradingPositionWorkerFactory     = tradingPositionWorkerFactory ?? throw new ArgumentNullException(nameof(tradingPositionWorkerFactory));
     _tradingPositionService           = tradingPositionService ?? throw new ArgumentNullException(nameof(tradingPositionService));
     _configurationService             = configurationService ?? throw new ArgumentNullException(nameof(configurationService));
     _tradingEventsObserver            = tradingEventsObserver ?? throw new ArgumentNullException(nameof(tradingEventsObserver));
     _loggingService = loggingService ?? throw new ArgumentNullException(nameof(loggingService));
 }
Beispiel #8
0
 public CollectorService(CandleLoadingService candleLoadingService)
 {
     _candleLoadingService = candleLoadingService;
 }
        protected override ConditionCheckingResult CheckConditions(CurrencyPair currencyPair)
        {
            var settings = ConfigurationService.GetTradingSettings();
            var moment   = settings.Moment ?? DateTime.UtcNow;

            var conditionCheckingResult = new ConditionCheckingResult()
            {
                ResultType = ConditionCheckingResultType.Failed
            };

            var firstFrameMACDSettings = new MACDSettings
            {
                EMAPeriod1   = 12,
                EMAPeriod2   = 26,
                SignalPeriod = 9
            };

            var firstFrameCandles = CandleLoadingService.LoadCandles(
                currencyPair.Id,
                settings.Period.GetHigherFramePeriod(),
                firstFrameMACDSettings.RequiredCandleRangeSize,
                moment)
                                    .OrderBy(candle => candle.Moment)
                                    .ToList();

            var firstFrameMACDValues = IndicatorComputingService.ComputeMACD(
                firstFrameCandles,
                firstFrameMACDSettings.EMAPeriod1,
                firstFrameMACDSettings.EMAPeriod2,
                firstFrameMACDSettings.SignalPeriod)
                                       .OfType <MACDValue>()
                                       .ToList();

            var firstFrameCurrentMACDValue     = firstFrameMACDValues.ElementAtOrDefault(firstFrameMACDValues.Count - 1);
            var firstFrameOnePreviousMACDValue = firstFrameMACDValues.ElementAtOrDefault(firstFrameMACDValues.Count - 2);

            //If all valuable parameters are not null
            if (firstFrameCurrentMACDValue?.Histogram == null ||
                firstFrameOnePreviousMACDValue?.Histogram == null)
            {
                return(conditionCheckingResult);
            }

            //if MACD higher then Signal then it is Bullish trend
            //if Histogram is rising
            if (!(firstFrameCurrentMACDValue.MACD > 0 ||
                  firstFrameCurrentMACDValue.Histogram.Value >= 0 ||
                  firstFrameCurrentMACDValue.Histogram.Value > firstFrameOnePreviousMACDValue.Histogram))
            {
                return(conditionCheckingResult);
            }

            var rsiSettings = new RSISettings
            {
                Period = 14
            };

            var secondFrameTargetPeriodCandles = CandleLoadingService.LoadCandles(
                currencyPair.Id,
                settings.Period,
                rsiSettings.Period + 2,
                moment)
                                                 .OrderBy(candle => candle.Moment)
                                                 .ToList();

            var candlesCount = secondFrameTargetPeriodCandles.Count;

            if (candlesCount < rsiSettings.Period)
            {
                return(conditionCheckingResult);
            }

            var secondFrameCurrentCandle = secondFrameTargetPeriodCandles.ElementAtOrDefault(secondFrameTargetPeriodCandles.Count - 1);

            if (secondFrameCurrentCandle?.VolumeInBaseCurrency == null)
            {
                return(conditionCheckingResult);
            }

            var lowerPeriodCandles = CandleLoadingService.LoadCandles(
                currencyPair.Id,
                settings.Period.GetLowerFramePeriod(),
                rsiSettings.Period,
                moment)
                                     .OrderBy(candle => candle.Moment)
                                     .ToList();

            if (!lowerPeriodCandles.Any())
            {
                throw new NoNullAllowedException("No candles loaded");
            }
            var currentLowPeriodCandle = lowerPeriodCandles.Last();

            if (secondFrameCurrentCandle.Moment != currentLowPeriodCandle.Moment)
            {
                var lastLowPeriodCandles = lowerPeriodCandles
                                           .Where(item => item.Moment > secondFrameCurrentCandle.Moment)
                                           .OrderBy(item => item.Moment)
                                           .ToList();

                if (lastLowPeriodCandles.Any())
                {
                    secondFrameTargetPeriodCandles.Add(new Candle
                    {
                        Moment                = lastLowPeriodCandles.Last().Moment,
                        MaxPrice              = lastLowPeriodCandles.Max(item => item.MaxPrice),
                        MinPrice              = lastLowPeriodCandles.Min(item => item.MinPrice),
                        OpenPrice             = lastLowPeriodCandles.First().OpenPrice,
                        ClosePrice            = lastLowPeriodCandles.Last().ClosePrice,
                        VolumeInBaseCurrency  = lastLowPeriodCandles.Sum(item => item.VolumeInBaseCurrency),
                        VolumeInQuoteCurrency = lastLowPeriodCandles.Sum(item => item.VolumeInQuoteCurrency)
                    });
                }
            }

            var period = (candlesCount - 2) > rsiSettings.Period ? rsiSettings.Period : candlesCount - 2;
            var secondFrameRSIValues = IndicatorComputingService.ComputeRelativeStrengthIndex(
                secondFrameTargetPeriodCandles,
                period)
                                       .OfType <SimpleIndicatorValue>()
                                       .ToList();

            var secondFrameCurrentRSIValue     = secondFrameRSIValues.ElementAtOrDefault(secondFrameRSIValues.Count - 1);
            var secondFrameOnePreviousRSIValue = secondFrameRSIValues.ElementAtOrDefault(secondFrameRSIValues.Count - 2);

            if (secondFrameCurrentRSIValue?.Value == null || secondFrameOnePreviousRSIValue?.Value == null)
            {
                return(conditionCheckingResult);
            }

            var rsiTopBorder = 45;

            if (firstFrameCurrentMACDValue.MACD > 0 && firstFrameCurrentMACDValue.Histogram.Value >= 0)
            {
                rsiTopBorder = 65;
            }
            if (firstFrameCurrentMACDValue.MACD > 0 || firstFrameCurrentMACDValue.Histogram.Value >= 0)
            {
                rsiTopBorder = 60;
            }
            if (secondFrameCurrentRSIValue.Value > rsiTopBorder || secondFrameCurrentRSIValue.Value < 25)
            {
                return(conditionCheckingResult);
            }

            if (secondFrameCurrentRSIValue.Value < secondFrameOnePreviousRSIValue.Value)
            {
                return(conditionCheckingResult);
            }

            conditionCheckingResult.ResultType = ConditionCheckingResultType.Passed;
            return(conditionCheckingResult);
        }