Пример #1
0
        public async static Task <GetCoinMetadataResponse> GetCoinMetadata(string symbol, string id, string baseCoinSymbol = "BTC")
        {
            var Response = new GetCoinMetadataResponse();
            var List     = await GetCoinList();

            if (!List.ContainsKey(symbol))
            {
                var Client = CoinMarketCapClient.GetInstance();
                Response.Details = await GetCoinTicker(id);

                return(Response);
            }

            if (Exchanges == null)
            {
                Exchanges = await GetExchanges();
            }

            var CryptoId      = Int32.Parse(List[symbol].Id);
            var SnapshotTask  = GetCoinSnapshot(CryptoId);
            var TickerTask    = GetCoinTicker(id);
            var SocialTask    = GetSocialStats(CryptoId);
            var ChartDataTask = GetCandleData(symbol, baseCoinSymbol);

            await Task.WhenAll(SnapshotTask, TickerTask, ChartDataTask, SocialTask);

            var ExchangeList = Exchanges.Where(x => x.Value.ContainsKey(symbol)).Select(x => x.Key).ToList();

            Response.Metadata    = SnapshotTask.Result;
            Response.Details     = TickerTask.Result;
            Response.CandleData  = ChartDataTask.Result;
            Response.SocialStats = SocialTask.Result;
            Response.Exchanges   = ExchangeList;
            return(Response);
        }
Пример #2
0
        public async static Task <CoinDetails> GetCoinTicker(string id)
        {
            CoinDetails Coin = null;

            var Client = CoinMarketCapClient.GetInstance();
            var Ticker = await Client.GetTickerAsync(id);

            Coin = new CoinDetails()
            {
                AvailableSupply = Ticker.AvailableSupply,
                Id                  = Ticker.Id,
                Name                = Ticker.Name,
                PercentChange1h     = Ticker.PercentChange1h,
                PercentChange24h    = Ticker.PercentChange24h,
                PercentChange7d     = Ticker.PercentChange7d,
                PriceBtc            = Ticker.PriceBtc,
                Rank                = Ticker.Rank,
                Symbol              = Ticker.Symbol,
                TotalSupply         = Ticker.TotalSupply,
                LastUpdatedUnixTime = Ticker.LastUpdatedUnixTime,
                LastUpdated         = Ticker.LastUpdated,
                MarketCapUsd        = Ticker.MarketCapUsd,
                MarketCapOther      = Ticker.MarketCapOther.ToEntity(),
                PriceOther          = Ticker.PriceOther.ToEntity(),
                PriceUsd            = Ticker.PriceUsd,
                Volume24hOther      = Ticker.Volume24hOther.ToEntity(),
                Volume24hUsd        = Ticker.Volume24hUsd
            };

            return(Coin);
        }
Пример #3
0
        public async static Task <MarketInfo> GetGlobalStats()
        {
            var Client = CoinMarketCapClient.GetInstance();
            var Stats  = await Client.GetGlobalDataAsync();

            return(Stats.ToEntity());
        }
 public CoinMarketCapTests()
 {
     _client = CoinMarketCapClient.GetInstance();
 }
Пример #5
0
 public CoinMarketManagerController()
 {
     _client = CoinMarketCapClient.GetInstance();
     //  _client = new CoinMarketCapClient();
 }
Пример #6
0
        public async static Task <List <CoinDetails> > GetTicker()
        {
            var Coins = new List <CoinDetails>();

            var Client     = CoinMarketCapClient.GetInstance();
            var TickerList = await Client.GetTickerListAsync(1000);

            TickerList.Reverse();
            try
            {
                var Tasks = new List <Task <KeyValuePair <long, decimal> > >();
                foreach (var Ticker in TickerList)
                {
                    int?daysOld = null;

                    double?Vol = 0;

                    try
                    {
                        Vol = Ticker.Volume24hUsd.GetValueOrDefault();
                    }
                    catch { }

                    try
                    {
                        daysOld = GetCoinAgeInDays(Ticker.Symbol, Ticker.Id);
                    }
                    catch (Exception ex)
                    {
                        var E = ex;
                        Debug.WriteLine(ex.Message);
                        if (ex.InnerException != null)
                        {
                            Debug.WriteLine(ex.InnerException.Message);
                        }
                    }

                    var Info = new CoinDetails()
                    {
                        AvailableSupply = Ticker.AvailableSupply.GetValueOrDefault(),
                        Id                  = Ticker.Id,
                        Name                = Ticker.Name,
                        PercentChange1h     = Ticker.PercentChange1h.GetValueOrDefault(),
                        PercentChange24h    = Ticker.PercentChange24h.GetValueOrDefault(),
                        PercentChange7d     = Ticker.PercentChange7d.GetValueOrDefault(),
                        PriceBtc            = Ticker.PriceBtc,
                        Rank                = Ticker.Rank,
                        Symbol              = Ticker.Symbol,
                        TotalSupply         = Ticker.TotalSupply.GetValueOrDefault(),
                        LastUpdatedUnixTime = Ticker.LastUpdatedUnixTime,
                        LastUpdated         = Ticker.LastUpdated,
                        MarketCapUsd        = Ticker.MarketCapUsd.GetValueOrDefault(),
                        MarketCapOther      = Ticker.MarketCapOther.ToEntity(),
                        PriceOther          = Ticker.PriceOther.ToEntity(),
                        PriceUsd            = Ticker.PriceUsd,
                        Volume24hOther      = Ticker.Volume24hOther.ToEntity(),
                        Volume24hUsd        = Vol,
                        DaysOld             = daysOld
                    };

                    Tasks.Add(GetATH(Ticker.Id));

                    Coins.Add(Info);
                }

                var Completed = await Task.WhenAll(Tasks);

                for (var i = 0; i < Completed.Length; i++)
                {
                    var ATH = Completed[i];

                    Coins[i].ATH     = (float)ATH.Value;
                    Coins[i].LastATH = FromUnixTime(ATH.Key);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                if (ex.InnerException != null)
                {
                    Debug.WriteLine(ex.InnerException.Message);
                }
            }
            return(Coins);
        }