private async Task UpdateCoinsAsync(ICoinBuilder builder) { this.Logger.LogInformation(message: "Updating All CoinInfos"); IReadOnlyCollection <ICoinInfo>[] allCoinInfos = await Task.WhenAll(this._coinClients.Select(this.GetCoinInfoAsync)); var cryptoInfos = allCoinInfos.SelectMany(selector: ci => ci) .GroupBy(keySelector: c => c.Symbol) .Select(selector: c => new { Symbol = c.Key, Coins = c.ToArray() }); foreach (var cryptoInfo in cryptoInfos) { ICoinInfo name = cryptoInfo.Coins[0]; Currency?currency = builder.Get(symbol: cryptoInfo.Symbol, name: name.Name); if (currency != null) { foreach (ICoinInfo info in cryptoInfo.Coins) { currency.AddDetails(info); } } } }
/// <summary> /// This will set the coin based on the currently open app. Note: this only currently works with Bitcoin based Ledger apps. /// </summary> public async Task SetCoinNumber() { var getCoinVersionResponse = await SendRequestAsync <GetCoinVersionResponse, GetCoinVersionRequest>(new GetCoinVersionRequest()); if (!getCoinVersionResponse.IsSuccess) { HandleErrorResponse(getCoinVersionResponse); } CurrentCoin = CoinUtility.GetCoinInfo(getCoinVersionResponse.ShortCoinName); }
/// <summary> /// Get the <paramref name="details" /> price in USD, BTC and ETH. /// </summary> /// <param name="details">The <see cref="CoinMarketCapCoin" />.</param> /// <returns></returns> public static string GetPrice(this ICoinInfo details) { StringBuilder priceStringBuilder = new StringBuilder(); if (details.PriceUsd != null) { priceStringBuilder.AppendLine(details.PriceUsd.AsUsdPrice(USD_PRICE_PRECISION)); } if (details.PriceBtc != null) { priceStringBuilder.AppendLine($"{details.PriceBtc} BTC"); } if (details.PriceEth != null) { priceStringBuilder.AppendLine($"{details.PriceEth} ETH"); } return(priceStringBuilder.ToString()); }
public void SetCoinNumber(uint coinNumber) { CurrentCoin = CoinUtility.GetCoinInfo(coinNumber); }
public void AddDetails(ICoinInfo details) { this._details.Add(details); }
public async Task CoinAsync([Remainder][Summary(text: "The symbol for the coin")] string symbol) { using (this.Context.Channel.EnterTypingState()) { try { Currency?currency = this._currencyManager.Get(symbol); if (currency?.IsFiat == false) { EmbedBuilder builder = new(); builder.WithTitle(currency.GetTitle()); CoinMarketCapCoin?details = currency.Getdetails <CoinMarketCapCoin>(); if (details != null) { builder.Color = details.DayChange > 0 ? Color.Green : Color.Red; AddAuthor(builder); builder.WithDescription(details.GetDescription()); builder.WithUrl(details.Url); if (currency.ImageUrl != null) { builder.WithThumbnailUrl(currency.ImageUrl); } builder.AddField(name: "Price", details.GetPrice()); builder.AddField(name: "Change", details.GetChange()); AddFooter(builder: builder, dateTime: details.LastUpdated); } else { ICoinInfo walletDetails = this.GetCoinInfo(currency); AddAuthor(builder); if (currency.ImageUrl != null) { builder.WithThumbnailUrl(currency.ImageUrl); } builder.AddField(name: "Price", walletDetails.GetPrice()); AddFooter(builder: builder, dateTime: walletDetails.LastUpdated); } await this.ReplyAsync(message : string.Empty, isTTS : false, builder.Build()); } else { await this.ReplyAsync($"sorry, {symbol} was not found"); } } catch (Exception e) { this._logger.LogError(new EventId(e.HResult), exception: e, message: e.Message); await this.ReplyAsync(message : "oops, something went wrong, sorry!"); } } }
/// <summary> /// This will set the coin based on the currently open app. Note: this only currently works with Bitcoin based Ledger apps. /// </summary> public async Task SetCoinNumber() { var getCoinVersionRequest = await SendRequestAsync <GetCoinVersionResponse, GetCoinVersionRequest>(new GetCoinVersionRequest()); CurrentCoin = CoinUtility.GetCoinInfo(getCoinVersionRequest.ShortCoinName); }