Пример #1
0
        public static List <Coin> GetCoinsInfoFromCoinsJson()
        {
            List <Coin> allCoins = new List <Coin>();

            /*
             * this has all coins "https://whattomine.com/calculators.json", but limited coin info , example
             * "id":74,"tag":"365","algorithm":"Keccak","lagging":true,"listed":false,"status":"No available stats","testing":false
             */
            string coinsUrl = "https://whattomine.com/coins.json";
            string response = InsighterService.GetHttpResponseText(coinsUrl);
            //  var values = CreaDev.Framework.Core.Utils.Serialization.DeSerialize<Dictionary<string, string>>(response);
            JObject json      = JObject.Parse(response);
            JToken  coinsjson = json.SelectToken("coins");

            foreach (JToken property in coinsjson.Children())
            {
                JProperty p        = property as JProperty;
                string    coinName = p.Name;
                string    values   = p.Value.ToString();
                WhatToMineCoinResponse whatToMineCoinResponse = CreaDev.Framework.Core.Utils.Serialization.DeSerialize <WhatToMineCoinResponse>(values);
                allCoins.Add(whatToMineCoinResponse.ToCoin(coinName));
            }

            return(allCoins);
        }
Пример #2
0
        public static Coin GetCoinInfo(int coinWhatToMineId)
        {
            //Note that coins it could throw an error if not active!
            //{"errors":["Could not find active coin with id 74"]}
            try
            {
                string coinUrl  = $"https://whattomine.com/coins/{coinWhatToMineId}.json";
                string response = InsighterService.GetHttpResponseText(coinUrl);
                //  var values = CreaDev.Framework.Core.Utils.Serialization.DeSerialize<Dictionary<string, string>>(response);
                WhatToMineCoinResponse whatToMineCoinResponse = CreaDev.Framework.Core.Utils.Serialization.DeSerialize <WhatToMineCoinResponse>(response);

                return(whatToMineCoinResponse.ToCoin(whatToMineCoinResponse.name));
            }
            catch
            {
            }

            return(null);
        }
        public static CryptoComparePriceResult GetCryptoComparePriceExchangeRate(string sourceCurrency, params string[] toCurrency)
        {
            string toCurrencyCsv = toCurrency.ToCsv(",");
            string coinUrl       = $"https://min-api.cryptocompare.com/data/price?fsym={sourceCurrency}&tsyms={toCurrencyCsv}";
            string response      = InsighterService.GetHttpResponseText(coinUrl);

            //  var values = CreaDev.Framework.Core.Utils.Serialization.DeSerialize<Dictionary<string, string>>(response);
            if (response.Contains("\"Response\":\"Error\""))
            {
                return(null);
            }
            Dictionary <string, double> whatToMineCoinResponse =
                CreaDev.Framework.Core.Utils.Serialization.DeSerialize <Dictionary <string, double> >(response);

            return(new CryptoComparePriceResult()
            {
                ExchangeRates = whatToMineCoinResponse,
                SourceCurrenceCode = sourceCurrency
            });
        }
Пример #4
0
        public static Dictionary <string, double> LoadCurrencies(bool removeSourceCurrencyFromKey = true)
        {
            string currencyApiUrl = "http://www.apilayer.net/api/live?access_key=ff139c408a9439cd66d94f7ee26a598b&format=1&source=USD";

            string respomseText       = InsighterService.GetHttpResponseText(currencyApiUrl);
            var    pricesDictResponse = JsonConvert.DeserializeObject <CurrencyPricesResponse>(respomseText);
            Dictionary <string, double> pricesDict = pricesDictResponse.quotes;

            if (removeSourceCurrencyFromKey)
            {
                Dictionary <string, double> withoutSourceCurrencyCode = new Dictionary <string, double>();
                foreach (var key in pricesDict.Keys)
                {
                    string newKey = key.Substring(3);
                    withoutSourceCurrencyCode.Add(newKey, pricesDict[key]);
                }
                pricesDict = withoutSourceCurrencyCode;
            }

            return(pricesDict);
        }
        public static List <CryptoComparePriceResult> GetCryptoComparePriceExchangeRateMultiSource(List <string> sourceCurrency, params string[] toCurrency)
        {
            List <CryptoComparePriceResult> comparePriceResults = new List <CryptoComparePriceResult>();


            string coinUrl  = $"https://min-api.cryptocompare.com/data/pricemulti?fsyms={sourceCurrency.ToCsv(",")}&tsyms={toCurrency.ToCsv(",")}";
            string response = InsighterService.GetHttpResponseText(coinUrl);
            //  var values = CreaDev.Framework.Core.Utils.Serialization.DeSerialize<Dictionary<string, string>>(response);
            Dictionary <string, Dictionary <string, double> > whatToMineCoinResponse =
                CreaDev.Framework.Core.Utils.Serialization.DeSerialize <Dictionary <string, Dictionary <string, double> > >(response);

            foreach (var key in whatToMineCoinResponse.Keys)
            {
                comparePriceResults.Add(new CryptoComparePriceResult()
                {
                    ExchangeRates      = whatToMineCoinResponse[key],
                    SourceCurrenceCode = key
                });
            }

            return(comparePriceResults);
        }