コード例 #1
0
        private List <TickerFormattedDto> LoadTickerFormattedDtos(ExchangePairTypeEnum exchangePairTypeEnum)
        {
            GetFormattedDataRequest tickerRequest = new GetFormattedDataRequest
            {
                From         = DateTime.Now.AddMinutes(-25),
                To           = DateTime.Now,
                PatterName   = _exchangeName.ToString().ToLower() + "_formatted",
                PairType     = (int)exchangePairTypeEnum,
                ExchangeType = _exchangeName == ElasticApiUrlHolder.ExchangeName.CEX ? 1 : 2,
                Size         = 25
            };

            GetFormattedDataResponse response = _elasticClient.GetFormattedTickers(tickerRequest);

            List <TickerFormattedDto> tickers = response?.hits?.hits?.Select(r => r._source).ToList();

            return(tickers);
        }
コード例 #2
0
        public GetChartDataResponse GetChartData(GetChartDataRequest request)
        {
            GetFormattedDataRequest formattedDataRequest = new GetFormattedDataRequest
            {
                PatterName   = request.ExchangeType == 1 ? "cex_formatted" : "poloniex_formatted",
                From         = DateTime.Now.AddMinutes(-25),
                To           = DateTime.Now,
                ExchangeType = request.ExchangeType,
                size         = 300,
                PairType     = (int)ResolvePairTypeEnum(request.Symbol1, request.Symbol2)
            };

            GetFormattedDataResponse  formattedDataResponse = _elasticClient.GetFormattedTickers(formattedDataRequest);
            List <TickerFormattedDto> tickers = formattedDataResponse.hits.hits.Select(r => r._source).ToList();

            GetChartDataResponse response = new GetChartDataResponse
            {
                Success     = true,
                Error       = "",
                ChartPoints = new List <ChartPoint>(),
                EcoPoints   = new Dictionary <int, List <EcoPoint> >
                {
                    { 1, new List <EcoPoint>() },
                    { 2, new List <EcoPoint>() },
                    { 3, new List <EcoPoint>() }
                }
            };

            foreach (TickerFormattedDto corTicker in tickers)
            {
                response.ChartPoints.Add(new ChartPoint
                {
                    High   = corTicker.High,
                    Last   = corTicker.Last,
                    Low    = corTicker.Low,
                    Time   = corTicker.Time,
                    Volume = corTicker.Volume
                });
            }
            string pairName = request.Symbol1.ToLower() + "_" + request.Symbol2.ToLower();

            if (pairName == "btc_eth")
            {
                pairName = "eth_btc";
            }

            if (request.ShowRSI)
            {
                GetEcoIndexDataRequest ecoIndexDataRequest = new GetEcoIndexDataRequest
                {
                    PatterName = request.ExchangeType == 1 ? "cex_eco_index" : "poloniex_eco_index",
                    From       = DateTime.Now.AddMinutes(-25),
                    To         = DateTime.Now,
                    EcoIndexNr = (int)EcoIndexEnum.RSI,
                    size       = 300,
                    PairName   = pairName
                };

                GetEcoIndexDataResponse ecoIndexDataResponse = _elasticClient.GetEcoIndexData(ecoIndexDataRequest);
                List <EcoIndex>         ecoIndexDtos         = ecoIndexDataResponse.hits.hits.Select(r => r._source).ToList();

                List <EcoPoint> rsiPoints = response.EcoPoints.FirstOrDefault(k => k.Key == (int)EcoIndexEnum.RSI).Value;

                foreach (var ecoIndex in ecoIndexDtos)
                {
                    rsiPoints.Add(new EcoPoint
                    {
                        Id    = (int)EcoIndexEnum.RSI,
                        Time  = ecoIndex.Time,
                        Value = ecoIndex.Value
                    });
                }
            }

            if (request.ShowEMA)
            {
                GetEcoIndexDataRequest ecoIndexDataRequest = new GetEcoIndexDataRequest
                {
                    PatterName = request.ExchangeType == 1 ? "cex_eco_index" : "poloniex_eco_index",
                    From       = DateTime.Now.AddMinutes(-25),
                    To         = DateTime.Now,
                    EcoIndexNr = (int)EcoIndexEnum.EMA,
                    size       = 300,
                    PairName   = pairName
                };

                GetEcoIndexDataResponse ecoIndexDataResponse = _elasticClient.GetEcoIndexData(ecoIndexDataRequest);
                List <EcoIndex>         ecoIndexDtos         = ecoIndexDataResponse.hits.hits.Select(r => r._source).ToList();

                List <EcoPoint> emaPoints = response.EcoPoints.FirstOrDefault(k => k.Key == (int)EcoIndexEnum.EMA).Value;

                foreach (var ecoIndex in ecoIndexDtos)
                {
                    emaPoints.Add(new EcoPoint
                    {
                        Id    = (int)EcoIndexEnum.EMA,
                        Time  = ecoIndex.Time,
                        Value = ecoIndex.Value
                    });
                }
            }

            if (request.ShowFI)
            {
                GetEcoIndexDataRequest ecoIndexDataRequest = new GetEcoIndexDataRequest
                {
                    PatterName = request.ExchangeType == 1 ? "cex_eco_index" : "poloniex_eco_index",
                    From       = DateTime.Now.AddMinutes(-25),
                    To         = DateTime.Now,
                    EcoIndexNr = (int)EcoIndexEnum.ForceIndex,
                    size       = 300,
                    PairName   = pairName
                };

                GetEcoIndexDataResponse ecoIndexDataResponse = _elasticClient.GetEcoIndexData(ecoIndexDataRequest);
                List <EcoIndex>         ecoIndexDtos         = ecoIndexDataResponse.hits.hits.Select(r => r._source).ToList();

                List <EcoPoint> emaPoints = response.EcoPoints.FirstOrDefault(k => k.Key == (int)EcoIndexEnum.ForceIndex).Value;

                foreach (var ecoIndex in ecoIndexDtos)
                {
                    emaPoints.Add(new EcoPoint
                    {
                        Id    = (int)EcoIndexEnum.ForceIndex,
                        Time  = ecoIndex.Time,
                        Value = ecoIndex.Value
                    });
                }
            }

            return(response);
        }