public static ApiFunction ToApiFunction(this TechIndicatorType techIndicatorType)
        {
            return((techIndicatorType) switch
            {
                TechIndicatorType.SMA => ApiFunction.SMA,
                TechIndicatorType.EMA => ApiFunction.EMA,
                TechIndicatorType.WMA => ApiFunction.WMA,
                TechIndicatorType.DEMA => ApiFunction.DEMA,
                TechIndicatorType.TEMA => ApiFunction.TEMA,
                TechIndicatorType.TRIMA => ApiFunction.TRIMA,
                TechIndicatorType.KAMA => ApiFunction.KAMA,
                TechIndicatorType.MAMA => ApiFunction.MAMA,
                TechIndicatorType.VWAP => ApiFunction.VWAP,
                TechIndicatorType.T3 => ApiFunction.T3,
                TechIndicatorType.MACD => ApiFunction.MACD,
                TechIndicatorType.MACDEXT => ApiFunction.MACDEXT,
                TechIndicatorType.STOCH => ApiFunction.STOCH,
                TechIndicatorType.STOCHF => ApiFunction.STOCHF,
                TechIndicatorType.RSI => ApiFunction.RSI,
                TechIndicatorType.STOCHRSI => ApiFunction.STOCHRSI,
                TechIndicatorType.WILLR => ApiFunction.WILLR,
                TechIndicatorType.ADX => ApiFunction.ADX,
                TechIndicatorType.ADXR => ApiFunction.ADXR,
                TechIndicatorType.APO => ApiFunction.APO,
                TechIndicatorType.PPO => ApiFunction.PPO,
                TechIndicatorType.MOM => ApiFunction.MOM,
                TechIndicatorType.BOP => ApiFunction.BOP,
                TechIndicatorType.CCI => ApiFunction.CCI,
                TechIndicatorType.CMO => ApiFunction.CMO,
                TechIndicatorType.ROC => ApiFunction.ROC,
                TechIndicatorType.ROCR => ApiFunction.ROCR,
                TechIndicatorType.AROON => ApiFunction.AROON,
                TechIndicatorType.AROONOSC => ApiFunction.AROONOSC,
                TechIndicatorType.MFI => ApiFunction.MFI,
                TechIndicatorType.TRIX => ApiFunction.TRIX,
                TechIndicatorType.ULTOSC => ApiFunction.ULTOSC,
                TechIndicatorType.DX => ApiFunction.DX,
                TechIndicatorType.MINUS_DI => ApiFunction.MINUS_DI,
                TechIndicatorType.PLUS_DI => ApiFunction.PLUS_DI,
                TechIndicatorType.MINUS_DM => ApiFunction.MINUS_DM,
                TechIndicatorType.PLUS_DM => ApiFunction.PLUS_DM,
                TechIndicatorType.BBANDS => ApiFunction.BBANDS,
                TechIndicatorType.MIDPOINT => ApiFunction.MIDPOINT,
                TechIndicatorType.MIDPRICE => ApiFunction.MIDPRICE,
                TechIndicatorType.SAR => ApiFunction.SAR,
                TechIndicatorType.TRANGE => ApiFunction.TRANGE,
                TechIndicatorType.ATR => ApiFunction.ATR,
                TechIndicatorType.NATR => ApiFunction.NATR,
                TechIndicatorType.AD => ApiFunction.AD,
                TechIndicatorType.ADOSC => ApiFunction.ADOSC,
                TechIndicatorType.OBV => ApiFunction.OBV,
                TechIndicatorType.HT_TRENDLINE => ApiFunction.HT_TRENDLINE,
                TechIndicatorType.HT_SINE => ApiFunction.HT_SINE,
                TechIndicatorType.HT_TRENDMODE => ApiFunction.HT_TRENDMODE,
                TechIndicatorType.HT_DCPERIOD => ApiFunction.HT_DCPERIOD,
                TechIndicatorType.HT_DCPHASE => ApiFunction.HT_DCPHASE,
                TechIndicatorType.HT_PHASOR => ApiFunction.HT_PHASOR,

                _ => throw new ArgumentOutOfRangeException(nameof(techIndicatorType))
            });
Ejemplo n.º 2
0
        private static void AssertTechIndicatorResultValid(
            TechIndicatorTimeSeries timeSeries,
            Interval interval,
            TechIndicatorType indicatorType,
            int expectedParamsCount)
        {
            timeSeries.Should().NotBeNull()
            .And.Match <TechIndicatorTimeSeries>(ti =>
                                                 ti.Interval == interval &&
                                                 ti.IndicatorType == indicatorType);

            timeSeries.MetaData.Should().NotBeNull()
            .And.HaveCountGreaterThan(1);

            timeSeries.DataPoints.Should().NotBeNull()
            .And.HaveCountGreaterThan(1)
            .And.NotContainNulls()
            .And.OnlyContain(dp => IsDataPointValid(dp, expectedParamsCount));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve technical indicators data
        /// </summary>
        /// <param name="client"></param>
        /// <param name="symbol"></param>
        /// <param name="indicatorType"></param>
        /// <param name="interval"></param>
        /// <param name="additionalParameters"></param>
        /// <returns></returns>
        /// <exception cref="AlphaVantageException"></exception>
        public static async Task <TechIndicatorTimeSeries> GetTechIndicatorTimeSeriesAsync(this AlphaVantageClient client,
                                                                                           string symbol,
                                                                                           TechIndicatorType indicatorType,
                                                                                           Interval interval,
                                                                                           Dictionary <string, string>?additionalParameters = null)
        {
            if (indicatorType == TechIndicatorType.VWAP && interval.IsIntraday() == false)
            {
                throw new AlphaVantageException("VWAP support only intraday intervals: 1min, 5min, 15min, 30min, 60min");
            }

            var query = additionalParameters ?? new Dictionary <string, string>();

            query.Add(ApiQueryConstants.IntervalQueryVar, interval.ConvertToQueryString());
            query.Add(ApiQueryConstants.SymbolQueryVar, symbol);
            var function = indicatorType.ToApiFunction();

            var typedClient = new TechnicalIndicatorsClient(client);
            var result      = await typedClient.RequestApiAsync(Parser, function, query);

            result.IndicatorType = indicatorType;
            result.Interval      = interval;

            return(result);
        }