private Dictionary <int, List <EcoIndex> > GetAllExchangeEcoIndexValues() { Dictionary <int, List <EcoIndex> > allIndexes = new Dictionary <int, List <EcoIndex> > { { 1, new List <EcoIndex>() }, { 2, new List <EcoIndex>() }, }; List <string> allCurrencies = new List <string> { "btc_usd", "eth_usd", "eth_btc", "eth_eur", "btc_eur" }; List <int> allEcoIndexes = new List <int> { (int)EcoIndexEnum.RSI, (int)EcoIndexEnum.EMA, (int)EcoIndexEnum.ForceIndex }; foreach (var currIndex in allIndexes) { foreach (string currencyPair in allCurrencies) { foreach (int ecoIndex in allEcoIndexes) { GetEcoIndexDataRequest ecoIndexDataRequest = new GetEcoIndexDataRequest { PatterName = currIndex.Key == 1 ? "cex_eco_index" : "poloniex_eco_index", From = DateTime.Now.AddMinutes(-2), To = DateTime.Now, EcoIndexNr = ecoIndex, size = 1, PairName = currencyPair }; GetEcoIndexDataResponse ecoIndexDataResponse = _elasticClient.GetEcoIndexData(ecoIndexDataRequest); EcoIndex newEcoIndex = ecoIndexDataResponse.hits.hits.FirstOrDefault()?._source; if (newEcoIndex != null) { currIndex.Value.Add(newEcoIndex); } } } } return(allIndexes); }
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); }