public ExtendedInfoModel GetDetails(AvailableExchanges name) { var result = new ExtendedInfoModel(); try { var exchange = _context.Exchange.FirstOrDefault(f => f.Name == name.ToString()); result = new ExtendedInfoModel { Name = exchange.Name, ImageUrl = exchange.ImageUrl, Country = exchange.Country, Type = exchange.Type, Description = exchange.Description, Markets = exchange.Market.Where(w => w.Symbol.Any()).Select(m => m.Name).ToList() }; } catch (Exception ex) { _logger.Information($"ExcangesService.GetDetails(name: {name})"); _logger.Error(ex.Message); return(result); } return(result); }
public bool SaveSymbolsForExchange(AvailableExchanges name) { try { IBaseExchangeClient exchangeClient = _exchangesData.GetClientInstance(name); var symbols = exchangeClient.GetSymbols().ToList(); List <MarketModel> markets = FindAndPopulateDistinctMarketsForExchange(symbols); #region For Testing ////test if all symbols are distributed to different markets //var totalSimbolCount = symbols.Count; //var simbolCountInMarkets = 0; //foreach (var market in markets) //{ // simbolCountInMarkets += market.CurrencyPairs.Count; //} //if (simbolCountInMarkets == totalSimbolCount) //{ // //success // totalSimbolCount = 0; //} #endregion var exchange = _context.Exchange.FirstOrDefault(e => e.Name == name.ToString()); if (exchange.Market.Any()) { return(false); } foreach (var market in markets) { var marketToSave = new Market { Exchange = exchange, Name = market.Name, StatusId = (int)Statuses.Active, }; _context.Market.Add(marketToSave); foreach (var pair in market.Pairs) { var symbolToSave = new Symbol { Market = marketToSave, Name = pair, StatusId = (int)Statuses.Active }; _context.Symbol.Add(symbolToSave); } } _context.SaveChanges(); } catch (Exception ex) { _logger.Information($"ExchangesService.SaveSymbolsForExchange(name: {name})"); _logger.Error(ex.Message); return(false); } return(true); }
public bool DeleteAllSymbolsForExchange(AvailableExchanges name) { try { var exchange = _context.Exchange.FirstOrDefault(e => e.Name == name.ToString()); _context.Symbol.RemoveRange(exchange.Market.SelectMany(s => s.Symbol)); _context.Market.RemoveRange(exchange.Market); _context.SaveChanges(); } catch (Exception ex) { _logger.Information($"ExchangesService.DeleteAllSymbolsForExchange(name: {name})"); _logger.Error(ex.Message); return(false); } return(true); }