Exemplo n.º 1
0
        public void AddStrategy(Strategy strategy, ITimeService timeService, int weight = 50)
        {
            if (this._traceStatusId != TraceStatus.Prepare.Id)
            {
                throw new TrendAnalysisDomainException("Adding Strategy can only happened in prepare status.");
            }
            if (timeService == null)
            {
                throw new TrendAnalysisDomainException("Time service is not provided when operating on trace.");
            }
            if (this._tradeStrategies.Where(t => t.Strategy == strategy).SingleOrDefault() != null)
            {
                throw new TrendAnalysisDomainException("Could not at the same strategy twice.");
            }


            var currentCandleDateTime = strategy.GetCurrentCandleDateTime(timeService);
            var signal = new TradeSignal(this.TraceId, currentCandleDateTime, 1, TradingSignalType.Hold.Id);;

            var strategyToAdd = new TradeStrategy(
                this.TraceId,
                Guid.NewGuid().ToString(),
                strategy ?? throw new TrendAnalysisDomainException("The strategy is not provided when create new trade strategy."),
                weight,
                signal
                );

            this._tradeStrategies.Add(strategyToAdd);
        }
Exemplo n.º 2
0
 public TradeStrategy(string traceId, string strategyId, Strategy strategy, int weight, TradeSignal tradeSignal) : this()
 {
     this.TraceId     = traceId ?? throw new TrendAnalysisDomainException("The trace Id is not provided when create new trade strategy.");
     this.StrategyId  = strategyId ?? throw new TrendAnalysisDomainException("The strategy Id is not provided when create new trade strategy.");
     this.Strategy    = strategy ?? throw new TrendAnalysisDomainException("The strategy is not provided when create new trade strategy.");
     this.Weight      = weight > 0 && weight <= 100 ? weight : throw new TrendAnalysisDomainException("The weight must be larger than 0 and smaller than 100 for trade strategy.");
     this.WarmUp      = strategy.MinimumAmountOfCandles >= 0 ? strategy.MinimumAmountOfCandles : throw new TrendAnalysisDomainException("The warm up must be equal or larger than 0 for trade strategy.");
     this.TradeSignal = tradeSignal ?? throw new TrendAnalysisDomainException("The trade signal is not provided.");
 }
Exemplo n.º 3
0
        public void Analysis(IEnumerable <Candle> candles, IIndicatorService indicatorService)
        {
            var lastCandle = candles.Last();

            if (lastCandle.Timestamp == this.TradeSignal.SignalCandleDateTime)
            {
                return;
            }

            var signalType = this.Strategy.Analysis(candles, indicatorService);

            this.TradeSignal = new TradeSignal(this.TraceId, lastCandle.Timestamp, lastCandle.Close, signalType.Id);
        }