Beispiel #1
0
        public async Task Price([Remainder, Summary("The symbol for the coin")] string symbol)
        {
            using (this.Context.Channel.EnterTypingState())
            {
                try
                {
                    Currency currency = this._currencyManager.Get(symbol);

                    if (currency != null)
                    {
                        CoinMarketCapCoin details = currency.Getdetails <CoinMarketCapCoin>();
                        await this.ReplyAsync($"{currency.Symbol} - ${details.GetPriceSummary()} ({details.GetChangeSummary()})");
                    }
                    else
                    {
                        await this.ReplyAsync($"sorry, {symbol} was not found");
                    }
                }
                catch (Exception e)
                {
                    this._logger.LogError(new EventId(e.HResult), e, e.Message);
                    await this.ReplyAsync($"oops, something went wrong, sorry!");

                    return;
                }
            }
        }
        /// <summary>
        /// Get the <paramref name="details"/> description, including market cap, rank and 24H volume.
        /// </summary>
        /// <param name="details">The <see cref="CoinMarketCapCoin"/>.</param>
        /// <returns></returns>
        public static string GetDescription(this CoinMarketCapCoin details)
        {
            StringBuilder descriptionBuilder = new StringBuilder();

            descriptionBuilder.AppendLine($"Market cap {details.MarketCap.AsUsdPrice()} (Rank {details.Rank})");
            descriptionBuilder.AppendLine($"24 hour volume: {details.Volume.AsUsdPrice()}");
            return(descriptionBuilder.ToString());
        }
        /// <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 CoinMarketCapCoin details)
        {
            StringBuilder priceStringBuilder = new StringBuilder();

            priceStringBuilder.AppendLine(details.PriceUsd.AsUsdPrice(UsdPricePrecision));
            priceStringBuilder.AppendLine($"{details.PriceBtc} BTC");
            priceStringBuilder.AppendLine($"{details.PriceEth} ETH");
            return(priceStringBuilder.ToString());
        }
        /// <summary>
        /// Get information about the price change from last hour, day and week.
        /// </summary>
        /// <param name="details">The <see cref="CoinMarketCapCoin"/>.</param>
        /// <returns></returns>
        public static string GetChange(this CoinMarketCapCoin details)
        {
            StringBuilder changeStringBuilder = new StringBuilder();

            changeStringBuilder.AppendLine($"Hour: {details.HourChange.AsPercentage()}");
            changeStringBuilder.AppendLine($"Day: {details.DayChange.AsPercentage()}");
            changeStringBuilder.AppendLine($"Week: {details.WeekChange.AsPercentage()}");
            return(changeStringBuilder.ToString());
        }
Beispiel #5
0
        public async Task Coin([Remainder, Summary("The symbol for the coin")] string symbol)
        {
            using (this.Context.Channel.EnterTypingState())
            {
                try
                {
                    Currency currency = this._currencyManager.Get(symbol);

                    if (currency != null)
                    {
                        EmbedBuilder builder = new EmbedBuilder();
                        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.AddInlineField("Price", details.GetPrice());
                            builder.AddInlineField("Change", details.GetChange());
                            AddFooter(builder, details.LastUpdated);
                        }

                        await this.ReplyAsync(string.Empty, false, builder.Build());
                    }
                    else
                    {
                        await this.ReplyAsync($"sorry, {symbol} was not found");
                    }
                }
                catch (Exception e)
                {
                    this._logger.LogError(new EventId(e.HResult), e, e.Message);
                    await this.ReplyAsync("oops, something went wrong, sorry!");

                    return;
                }
            }
        }
Beispiel #6
0
        private async Task MultiCoinReply(IList <Currency> coins, Color color, string title, string description)
        {
            EmbedBuilder builder = new EmbedBuilder();

            builder.WithTitle(title);
            builder.WithDescription(description);
            builder.Color = color;
            AddAuthor(builder);
            AddFooter(builder, coins.Max(c => c.Getdetails <CoinMarketCapCoin>().LastUpdated));

            foreach (Currency coin in coins)
            {
                CoinMarketCapCoin details = coin.Getdetails <CoinMarketCapCoin>();
                builder.Fields.Add(new EmbedFieldBuilder
                {
                    Name  = $"{coin.Name} ({coin.Symbol}) | {details.DayChange.AsPercentage()} | {details.GetPriceSummary()}",
                    Value = $"[{details.GetChangeSummary()}{Environment.NewLine}Cap {details.MarketCap.AsUsdPrice()} | Vol {details.Volume.AsUsdPrice()} | Rank {details.Rank}]({details.Url})"
                });
            }

            await this.ReplyAsync(string.Empty, false, builder.Build());
        }
 /// <summary>
 /// Get the <paramref name="details"/> price summary in USD and BTC.
 /// </summary>
 /// <param name="details"></param>
 /// <returns></returns>
 public static string GetPriceSummary(this CoinMarketCapCoin details)
 {
     return($"{details.PriceUsd.AsUsdPrice(UsdPricePrecision)}/{details.PriceBtc} BTC");
 }
 /// <summary>
 /// Get a summary about the price change from last hour, day and week.
 /// </summary>
 /// <param name="details"></param>
 /// <returns></returns>
 public static string GetChangeSummary(this CoinMarketCapCoin details)
 {
     return($"{details.HourChange.AsPercentage()} | {details.DayChange.AsPercentage()} | {details.WeekChange.AsPercentage()}");
 }
Beispiel #9
0
        public async Task Markets([Remainder][Summary("The input as a single coin symbol or a pair")] string input)
        {
            using (this.Context.Channel.EnterTypingState())
                try
                {
                    if (!this.GetCurrencies(input, out Currency primaryCurrency, out Currency secondaryCurrency))
                    {
                        await this.ReplyAsync($"Oops! I did not understand `{input}`.");

                        return;
                    }

                    List <MarketSummaryDto> markets = secondaryCurrency == null
                                                ? this._marketManager.Get(primaryCurrency).ToList()
                                                : this._marketManager.GetPair(primaryCurrency, secondaryCurrency).ToList();

                    if (!markets.Any())
                    {
                        await this.ReplyAsync($"sorry, no market details found for {input}");

                        return;
                    }

                    EmbedBuilder builder = new EmbedBuilder();
                    builder.WithTitle(primaryCurrency.GetTitle());
                    CoinMarketCapCoin details = primaryCurrency.Getdetails <CoinMarketCapCoin>();
                    if (details != null)
                    {
                        builder.WithUrl(details.Url);
                    }

                    AddAuthor(builder);

                    if (primaryCurrency.ImageUrl != null)
                    {
                        builder.WithThumbnailUrl(primaryCurrency.ImageUrl);
                    }

                    // Group by exchange, and if looking for a pair orderby volume
                    IEnumerable <IGrouping <string, MarketSummaryDto> > grouped = secondaryCurrency != null
                                                ? markets
                                                                                  .GroupBy(m => m.Market)
                                                                                  .OrderByDescending(g => g.Sum(m => m.Volume * m.Last))
                                                : markets
                                                                                  .GroupBy(m => m.Market);

                    foreach (IGrouping <string, MarketSummaryDto> group in grouped)
                    {
                        string    exchangeName = group.Key;
                        const int maxResults   = 3;
                        int       totalResults = group.Count();

                        StringBuilder marketDetails = new StringBuilder();
                        if (secondaryCurrency == null && totalResults > maxResults)
                        {
                            int diff = totalResults - maxResults;
                            if (totalResults < 10)
                            {
                                this.WriteMarketSummaries(marketDetails, group.Take(maxResults));

                                marketDetails.AppendLine();
                                marketDetails.AppendLine($"Found {diff} more {primaryCurrency.Symbol} market(s) at {exchangeName}:");
                                marketDetails.AppendLine(string.Join(", ", group.Skip(maxResults).Select(m => $"{m.BaseCurrrency.Symbol}/{m.MarketCurrency.Symbol}")));
                            }
                            else
                            {
                                marketDetails.AppendLine($"`Found {diff} more {primaryCurrency.Symbol} market(s) at {exchangeName}.`");
                            }
                        }
                        else
                        {
                            this.WriteMarketSummaries(marketDetails, group);
                        }

                        builder.AddField($"{exchangeName}", marketDetails);
                    }

                    DateTime?lastUpdated = markets.Min(m => m.LastUpdated);
                    AddFooter(builder, lastUpdated);

                    string operationName = (secondaryCurrency != null)
                                                ? $"{primaryCurrency.Name}/{secondaryCurrency.Name}"
                                                : primaryCurrency.Name;

                    await this.ReplyAsync($"Markets for `{operationName}`:", false, builder.Build());
                }
                catch (Exception e)
                {
                    this._logger.LogError(0, e, $"Something went wrong while processing the !markets command with input '{input}'");
                    await this.ReplyAsync("oops, something went wrong, sorry!");
                }
        }
 /// <summary>
 ///     Get the <paramref name="details" /> price summary in USD and BTC.
 /// </summary>
 /// <param name="details"></param>
 /// <returns></returns>
 public static string GetPriceSummary(this CoinMarketCapCoin details)
 {
     return($"{details.PriceUsd.AsUsdPrice(USD_PRICE_PRECISION)}/{details.PriceBtc} BTC");
 }