Beispiel #1
0
 /// <summary>
 /// Gets specific ticker with accompanying data.
 /// </summary>
 /// <param name="ID">ID of ticker to pull.</param>
 /// <param name="Currency">Fiat currency to convert to.</param>
 /// <returns>Ticker data.</returns>
 public static async Task <Ticker> GetTickerAsync(string ID, Currencies Currency = Currencies.USD) =>
 await Ticker.GetTickerAsync(ID, Currency).ConfigureAwait(false);
Beispiel #2
0
 /// <summary>
 /// Gets all available tickers with accompanying data.
 /// </summary>
 /// <param name="Currency">Fiat currency to convert to.</param>
 /// <returns>List of all tickers with data.</returns>
 public static async Task <List <Ticker> > GetAllTickersAsync(Currencies Currency = Currencies.USD) =>
 await Ticker.GetTickersAsync(Currency, 0, 0).ConfigureAwait(false);
Beispiel #3
0
 /// <summary>
 /// Gets a selection of tickers with accompanying data.
 /// </summary>
 /// <param name="Currency">Fiat currency to convert to.</param>
 /// <param name="Start">Rank to start from.</param>
 /// <param name="Limit">Number of tickers to return.</param>
 /// <returns>List of tickers with data.</returns>
 public static async Task <List <Ticker> > GetTickersAsync(Currencies Currency = Currencies.USD, int Start = 0, int Limit = 100) =>
 await Ticker.GetTickersAsync(Currency, Start, Limit).ConfigureAwait(false);
Beispiel #4
0
        private static async Task <Ticker> ParseSingleResponseAsync(string response, Currencies currency)
        {
            Ticker ToAdd = new Ticker();

            ToAdd.Currency = currency;
            using (JsonTextReader jtr = new JsonTextReader(new StringReader(response)))
            {
                while (await jtr.ReadAsync().ConfigureAwait(false))
                {
                    if (jtr.Value != null)
                    {
                        if (jtr.Value.ToString() == "id")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            ToAdd.ID = jtr.Value.ToString();
                        }
                        else if (jtr.Value.ToString() == "name")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            ToAdd.Name = jtr.Value.ToString();
                        }
                        else if (jtr.Value.ToString() == "symbol")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            ToAdd.Symbol = jtr.Value.ToString();
                        }
                        else if (jtr.Value.ToString() == "rank")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.Rank = Convert.ToInt32(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "price_usd")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.PriceUSD = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "price_btc")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.PriceBTC = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "24h_volume_usd")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.Volume24HourUSD = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "market_cap_usd")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.MarketCapUSD = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "available_supply")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.AvailableSupply = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "total_supply")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.TotalSupply = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "max_supply")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.MaxSupply = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "percent_change_1h")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.PercentChange1Hour = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "percent_change_24h")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.PercentChange24Hour = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "percent_change_7d")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.PercentChange7Day = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "last_updated")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.LastUpdated = Convert.ToInt32(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == "error")
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            ToAdd.Error = jtr.Value.ToString();
                        }
                        else if (jtr.Value.ToString() == string.Format("price_{0}", currency.ToString().ToLower()))
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.Price = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == string.Format("24h_volume_{0}", currency.ToString().ToLower()))
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.Volume24Hour = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else if (jtr.Value.ToString() == string.Format("market_cap_{0}", currency.ToString().ToLower()))
                        {
                            await jtr.ReadAsync().ConfigureAwait(false);

                            if (jtr.Value != null)
                            {
                                ToAdd.MarketCap = Convert.ToDouble(jtr.Value.ToString());
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (currency == Currencies.USD)
            {
                ToAdd.Price        = ToAdd.PriceUSD;
                ToAdd.Volume24Hour = ToAdd.Volume24HourUSD;
                ToAdd.MarketCap    = ToAdd.MarketCapUSD;
            }
            return(ToAdd);
        }