Exemplo n.º 1
0
 public static CandleChart FromMarket(Market market, CandlePeriod candlePeriod)
 {
     return(new CandleChart(
                Guid.NewGuid().ToString(),
                market.MarketId ?? throw new ExchangeAccessDomainException("The Market Id isn't provided."),
                candlePeriod != null ? candlePeriod.Id : throw new ExchangeAccessDomainException("The candle period is not provided."),
                market.BaseCurrency ?? throw new ExchangeAccessDomainException("The base currency is not provided."),
                market.QuoteCurrency ?? throw new ExchangeAccessDomainException("The quote currency is not provided."),
                market.Exchange != null ? market.Exchange.ExchangeId : throw new ExchangeAccessDomainException("The exchange is not provided.")
                ));
 }
        public static int GetOneCandleMinutesByPeriod(CandlePeriod candlePeriod)
        {
            var period = candlePeriod.Id;

            if (period == CandlePeriod.OneMinute.Id)
            {
                return(1);
            }
            else if (period == CandlePeriod.FiveMinutes.Id)
            {
                return(5);
            }
            else if (period == CandlePeriod.FifteenMinutes.Id)
            {
                return(15);
            }
            else if (period == CandlePeriod.ThirtyMinutes.Id)
            {
                return(30);
            }
            else if (period == CandlePeriod.OneHour.Id)
            {
                return(60);
            }
            else if (period == CandlePeriod.TwoHours.Id)
            {
                return(60 * 2);
            }
            else if (period == CandlePeriod.FourHours.Id)
            {
                return(60 * 4);
            }
            else if (period == CandlePeriod.OneDay.Id)
            {
                return(60 * 24);
            }
            else if (period == CandlePeriod.OneWeek.Id)
            {
                return(60 * 24 * 7);
            }

            throw new ArgumentOutOfRangeException("Could not recognize this candle period.");
        }
Exemplo n.º 3
0
        private void CheckCandleTimestamp(DateTime timestamp)
        {
            var period = this._candlePeriodId;

            if (period == CandlePeriod.OneMinute.Id || period == CandlePeriod.FiveMinutes.Id || period == CandlePeriod.FifteenMinutes.Id || period == CandlePeriod.ThirtyMinutes.Id)
            {
                //Seconds and MilliSeconds should be zero.
                if (timestamp.Second != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"Second\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }

                if (timestamp.Millisecond != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"MilliSecond\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }
            }
            else if (period == CandlePeriod.OneHour.Id || period == CandlePeriod.TwoHours.Id || period == CandlePeriod.FourHours.Id)
            {
                //Minutes and Seconds and MilliSeconds should be zero.
                if (timestamp.Minute != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"Minute\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }

                if (timestamp.Second != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"Second\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }

                if (timestamp.Millisecond != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"MilliSecond\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }
            }
            else if (period == CandlePeriod.OneDay.Id)
            {
                //Hours and Minutes and Seconds and MilliSeconds should be zero.
                if (timestamp.Hour != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"Hour\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }

                if (timestamp.Minute != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"Minute\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }

                if (timestamp.Second != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"Second\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }

                if (timestamp.Millisecond != 0)
                {
                    throw new ExchangeAccessDomainException($"The \"MilliSecond\" property in timestamp for the given candle should be zero on {CandlePeriod.From(period)} chart.");
                }
            }


            if (period == CandlePeriod.OneMinute.Id)
            {
            }
            else if (period == CandlePeriod.FiveMinutes.Id)
            {
                if (timestamp.Minute % 5 != 0)
                {
                    throw new ExchangeAccessDomainException("The minute property of timestamp must be divisible by 5 on 5m chart.");
                }
            }
            else if (period == CandlePeriod.FifteenMinutes.Id)
            {
                if (timestamp.Minute % 15 != 0)
                {
                    throw new ExchangeAccessDomainException("The minute property of timestamp must be divisible by 15 on 15m chart.");
                }
            }
            else if (period == CandlePeriod.ThirtyMinutes.Id)
            {
                if (timestamp.Minute % 30 != 0)
                {
                    throw new ExchangeAccessDomainException("The minute property of timestamp must be divisible by 30 on 30m chart.");
                }
            }
            else if (period == CandlePeriod.OneHour.Id)
            {
            }
            else if (period == CandlePeriod.TwoHours.Id)
            {
                if (timestamp.Hour % 2 != 0)
                {
                    throw new ExchangeAccessDomainException("The hour property of timestamp must be divisible by 2 on 2hr chart.");
                }
            }
            else if (period == CandlePeriod.FourHours.Id)
            {
                if (timestamp.Hour % 4 != 0)
                {
                    throw new ExchangeAccessDomainException("The hour property of timestamp must be divisible by 4 on 4hr chart.");
                }
            }
            else if (period == CandlePeriod.OneDay.Id)
            {
            }
            else if (period == CandlePeriod.OneWeek.Id)
            {
                if (timestamp.DayOfWeek != DayOfWeek.Monday)
                {
                    throw new ExchangeAccessDomainException("The DayOfWeek property of timestamp must be equal to Monday.");
                }
            }
        }