public async Task <IEnumerable <CryptoCurrencyDto> > GetAvailableCryptocurrencies()
        {
            // Call the external API using the product identifier as an URL parameter to
            string URL           = "https://data.messari.io/api/v2/assets";
            string urlParameters = "?fields=id,symbol,name,slug,metrics/market_data/price_usd,profile/general/overview/project_details";

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(URL);

            // Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            // List data response.
            var response = await client.GetAsync(urlParameters);

            if (response.IsSuccessStatusCode)
            {
                // Deserialize the response to a CryptoCurrencyDto model
                var cryptoCurrencies = await HttpResponseMessageExtensions.DeserializeJsonToList <CryptoCurrencyDto>(response, true);

                // Filter the list for BTC, ETH, USDT and XMR
                var filteredCryptoCurrencies = cryptoCurrencies.Where(c => c.Symbol == "BTC" || c.Symbol == "ETH" || c.Symbol == "USDT" || c.Symbol == "XMR").ToList();

                client.Dispose();

                return(filteredCryptoCurrencies);
            }
            else
            {
                throw new ApplicationException("Request failed to external API.");
            }
        }
        public async Task <Envelope <ExchangeDto> > GetExchanges(int pageNumber = 1)
        {
            HttpClient client = new HttpClient();

            // Call the external API with a paginated query and get all exchanges with fields required for the ExchangeDto model
            var getExhanges = "https://data.messari.io/api/v1/markets?page={pageNumber}&fields=id,exchange_name,exchange_slug,quote_asset_symbol,price_usd,last_trade_at";

            client.DefaultRequestHeaders.Accept.Clear();
            //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var response = await client.GetAsync(getExhanges);

            // Deserialize the response to a list - I would advise to use the HttpResponseMessageExtensions to deserialize and flatten the response
            var responseFlat = await HttpResponseMessageExtensions.DeserializeJsonToList <ExchangeDto>(response, true);

            // Create an envelope and add the list to the envelope and return that

            /*var envelope = new Envelope<ExchangeDto>
             * {
             *  Items = new List<ExchangeDto>(responseFlat);
             *
             * };*/
            //return envelope;
            return(null);
        }
Exemple #3
0
        public async Task <IEnumerable <CryptoCurrencyDto> > GetAvailableCryptocurrencies()
        {
            HttpClient client = new HttpClient();

            // Call the external API and get all cryptocurrencies with fields required for the CryptoCurrencyDto model
            var getCurrencies = "https://data.messari.io/api/v2/assets?fields=id,name,slug,symbol,metrics/market_data/price_usd,profile/general/overview/project_details";

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var response = await client.GetAsync(getCurrencies);

            // Deserializes the response to a list - I would advise to use the HttpResponseMessageExtensions to deserialize and flatten the response.
            var responseFlat = await HttpResponseMessageExtensions.DeserializeJsonToList <CryptoCurrencyDto>(response, true);

            // Return a filtered list where only the available cryptocurrencies BitCoin (BTC), Ethereum (ETH), Tether (USDT) and Monero (XMR) are within the list
            return(responseFlat.Where(s => s.Symbol == "BTC" || s.Symbol == "ETH" || s.Symbol == "USDT" || s.Symbol == "XMR"));
        }
Exemple #4
0
        public async Task <Envelope <ExchangeDto> > GetExchanges(int pageNumber = 1)
        {
            // Call the external API using the product identifier as an URL parameter to
            string URL           = "https://data.messari.io/api/v1/markets";
            string urlParameters = "?fields=exchange_id,exchange_name,exchange_slug,quote_asset_symbol,price_usd,last_trade_at&page=" + pageNumber;

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(URL);

            // Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            // List data response.
            var response = await client.GetAsync(urlParameters);

            if (response.IsSuccessStatusCode)
            {
                // Deserialize the response to a ExchangeDto model
                var exchanges = await HttpResponseMessageExtensions.DeserializeJsonToList <ExchangeDto>(response, true);

                // Create the enveloper
                var envelope = new Envelope <ExchangeDto>
                {
                    Items      = exchanges,
                    PageNumber = pageNumber
                };

                client.Dispose();

                return(envelope);
            }
            else
            {
                throw new Exception("Request failed to external API.");
            }
        }