Exemplo n.º 1
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadString(apiUrl);

            JObject jsonObject = JObject.Parse(jsonString);
            
            if (!jsonObject.Value<bool>("Success"))
            {
                throw new CoinApiException(jsonObject.Value<string>("Message"));
            }

            JArray jsonArray = jsonObject.Value<JArray>("Data");

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Exemplo n.º 2
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            ApiWebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            //get GPU coin info (scrypt, X11, etc)
            string jsonString = client.DownloadString(GetApiUrl());            
            Data.ApiResponse apiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString);

            //merge in ASIC coin info (sha-256, scrypt, etc)
            jsonString = client.DownloadString(GetAsicApiUrl());            
            Data.ApiResponse asicApiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString);
            foreach (string coinName in asicApiResponse.Coins.Keys)
                apiResponse.Coins[coinName] = asicApiResponse.Coins[coinName];

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (string coinName in apiResponse.Coins.Keys)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.Name = coinName;
                coinInformation.PopulateFromJson(apiResponse.Coins[coinName]);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Exemplo n.º 3
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();
            string jsonString = client.DownloadString(apiUrl);
            JObject jsonObject = JObject.Parse(jsonString);

            string resultStatus = jsonObject.Value<string>("status");
            if (!resultStatus.Equals("success", StringComparison.OrdinalIgnoreCase))
                throw new CoinApiException(resultStatus);

            List<CoinInformation> result = new List<CoinInformation>();

            JArray jsonArray = jsonObject.Value<JArray>("Data");
            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            CalculateProfitability(result);

            return result;
        }
Exemplo n.º 4
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            ApiWebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadFlakyString(apiUrl);

            JArray jsonArray = JArray.Parse(jsonString);

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Exemplo n.º 5
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = String.Empty;

            try
            {
                jsonString = client.DownloadString(apiUrl);
            }
            catch (WebException ex)
            {
                if ((ex.Status == WebExceptionStatus.ProtocolError) &&
                    (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadGateway))
                {
                    //try again 1 more time if error 502
                    Thread.Sleep(750);
                    jsonString = client.DownloadString(apiUrl);
                }
                else
                    throw;
            }

            JArray jsonArray = JArray.Parse(jsonString);

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Exemplo n.º 6
0
        private void NotifyCoinToMine(IApiContext apiContext, CoinInformation coin)
        {
            string value = coin.AverageProfitability.ToString(".#") + "%";
            string noun = "average profitability";

            switch (engineConfiguration.StrategyConfiguration.MiningBasis)
            {
                case Strategy.CoinMiningBasis.Difficulty:
                    value = coin.Difficulty.ToString(".####");
                    noun = "difficulty";
                    break;
                case Strategy.CoinMiningBasis.Price:
                    value = coin.Price.ToString(".########");
                    noun = "price";
                    break;
            }

            string infoUrl = apiContext.GetInfoUrl();

            PostNotification(coin.Symbol,
                String.Format("Consider mining {0} ({1} {2})",
                    coin.Symbol, value, noun),
                () =>
                    {
                        Process.Start(String.Format("https://www.google.com/search?q={0}+{1}+mining+pools",
                            coin.Symbol, coin.Name));
                    }, ToolTipIcon.Info, infoUrl);
        }
Exemplo n.º 7
0
 private static List<CoinInformation> CopyCoinInformation(List<CoinInformation> coinInformation)
 {
     List<CoinInformation> coinInformationCopy = new List<CoinInformation>();
     foreach (CoinInformation realCoin in coinInformation)
     {
         CoinInformation coinCopy = new CoinInformation();
         CopyPoco(realCoin, coinCopy);
         coinInformationCopy.Add(coinCopy);
     }
     return coinInformationCopy;
 }