public List <string> RunCommand(ChannelMessageEventDataModel messageEvent, GroupCollection arguments = null, bool useCache = true) { if (arguments == null || arguments.Count == 1) { throw new ArgumentException("Not enough arguments"); } string tickerName = arguments[1].Value; List <CoinMarketSymbolCacheModel> symbolCache = Cache.Get <List <CoinMarketSymbolCacheModel> >("CoinMarketSymbolCache"); if (symbolCache == null) { // 0 means all in CoinMarketCap-land List <TickerModel> symbolList = CoinMarketCapApi.Api.TickerApi.GetAllTickers(limit: 0).Result; symbolCache = symbolList.Select(symbol => new CoinMarketSymbolCacheModel { Name = symbol.TickerId, Symbol = symbol.Symbol }).ToList(); Cache.Set("CoinMarketSymbolCache", symbolCache, DateTimeOffset.Now.AddDays(1)); } foreach (CoinMarketSymbolCacheModel symbol in symbolCache) { if (!String.Equals(tickerName, symbol.Symbol, StringComparison.CurrentCultureIgnoreCase)) { continue; } tickerName = symbol.Name; break; } TickerModel ticker; try { ticker = CoinMarketCapApi.Api.TickerApi.GetTicker(tickerName).Result[0]; } catch (Exception e) { if (e.InnerException is CoinMarketCapApi.Exceptions.TickerNotFoundException) { return("Ticker not found".SplitInParts(430).ToList()); } throw; } return(CoinMarketCapHelpers.FormatTicker(ticker)); }
public List <string> RunCommand(ChannelMessageEventDataModel messageEvent, GroupCollection arguments = null, bool useCache = true) { const string tickerName = "bitcoin-cash"; TickerModel ticker; try { ticker = CoinMarketCapApi.Api.TickerApi.GetTicker(tickerName).Result[0]; } catch (Exception e) { if (e.InnerException is CoinMarketCapApi.Exceptions.TickerNotFoundException) { return("Ticker not found".SplitInParts(430).ToList()); } throw; } return(CoinMarketCapHelpers.FormatTicker(ticker)); }
public List <string> RunCommand(ChannelMessageEventDataModel messageEvent, GroupCollection arguments = null, bool useCache = true) { List <CoinMarketSymbolCacheModel> symbolCache = Cache.Get <List <CoinMarketSymbolCacheModel> >("CoinMarketSymbolCache"); if (symbolCache == null) { // 0 means all in CoinMarketCap-land List <TickerModel> symbolList = CoinMarketCapApi.Api.TickerApi.GetAllTickers(limit: 0).Result; symbolCache = symbolList.Select(symbol => new CoinMarketSymbolCacheModel { Name = symbol.TickerId, Symbol = symbol.Symbol }).ToList(); Cache.Set("CoinMarketSymbolCache", symbolCache, DateTimeOffset.Now.AddDays(1)); } string tickerName = symbolCache[new Random().Next(0, symbolCache.Count - 1)].Name; TickerModel ticker; try { ticker = CoinMarketCapApi.Api.TickerApi.GetTicker(tickerName).Result[0]; } catch (Exception e) { if (e.InnerException is CoinMarketCapApi.Exceptions.TickerNotFoundException) { return("Ticker not found".SplitInParts(430).ToList()); } throw; } return(CoinMarketCapHelpers.FormatTicker(ticker)); }