Exemple #1
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "",
            BaseCoin profitabilityBasis = BaseCoin.Bitcoin)
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl(profitabilityBasis);

            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;
        }
Exemple #2
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);
            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;
        }
Exemple #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 = 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;
        }
        public void InspectDetails(Device device, CoinConfiguration coinConfiguration, CoinInformation coinInformation,
            List<DeviceInformationResponse> deviceInformation, PoolInformationResponse poolInformation,
            List<DeviceDetailsResponse> deviceDetails, bool showWorkUtility)
        {
            this.deviceDetails = deviceDetails;
            this.deviceInformation = deviceInformation;

            noDetailsPanel.Visible = false;
            double hashrate = deviceInformation.Sum(di => di.AverageHashrate);
            double currentRate = deviceInformation.Sum(di => di.CurrentHashrate);

            hashrateLabel.Text = hashrate.ToHashrateString();
            currentRateLabel.Text = currentRate.ToHashrateString();

            workersGridView.Visible = (device.Kind == DeviceKind.PXY) &&
                (deviceInformation.Count > 0);
            workersTitleLabel.Visible = workersGridView.Visible;

            //Internet or Coin API could be down
            if (coinInformation != null)
            {
            }

            //device may not be configured
            if (coinConfiguration != null)
                cryptoCoinBindingSource.DataSource = coinConfiguration.Coin;
            else
                cryptoCoinBindingSource.DataSource = new CryptoCoin();

            deviceInformationResponseBindingSource.DataSource = deviceInformation;

            //may not be hashing yet
            if (deviceDetails != null)
                deviceDetailsResponseBindingSource.DataSource = deviceDetails;
            else
                deviceDetailsResponseBindingSource.DataSource = new DeviceDetailsResponse();

            deviceBindingSource.DataSource = device;

            switch (device.Kind)
            {
                case DeviceKind.CPU:
                    pictureBox1.Image = imageList1.Images[3];
                    break;
                case DeviceKind.GPU:
                    pictureBox1.Image = imageList1.Images[0];
                    break;
                case DeviceKind.USB:
                    pictureBox1.Image = imageList1.Images[1];
                    break;
                case DeviceKind.PXY:
                    pictureBox1.Image = imageList1.Images[2];
                    break;
            }

            nameLabel.Width = this.Width - nameLabel.Left - closeDetailsButton.Width;

            acceptedLabel.Text = deviceInformation.Sum(d => d.AcceptedShares).ToString();
            rejectedLabel.Text = deviceInformation.Sum(d => d.RejectedShares).ToString();
            errorsLabel.Text = deviceInformation.Sum(d => d.HardwareErrors).ToString();

            if (showWorkUtility)
            {
                utilityLabel.Text = deviceInformation.Sum(d => d.WorkUtility).ToString();
                utilityDataGridViewTextBoxColumn.DataPropertyName = "WorkUtility";
            }
            else
            {
                utilityLabel.Text = deviceInformation.Sum(d => d.Utility).ToString();
                utilityDataGridViewTextBoxColumn.DataPropertyName = "Utility";
            }
            utilityPrefixLabel.Text = showWorkUtility ? "Work utility:" : "Utility:";

            DeviceInformationResponse deviceInfo = (DeviceInformationResponse)deviceInformationResponseBindingSource.Current;
            if (deviceInfo != null)
            {
                if (deviceInfo.Temperature > 0)
                    tempLabel.Text = deviceInfo.Temperature + "°";
                else
                    tempLabel.Text = String.Empty;

                if (deviceInfo.FanPercent > 0)
                    fanLabel.Text = deviceInfo.FanPercent + "%";
                else
                    fanLabel.Text = String.Empty;
            }
            else
            {
                tempLabel.Text = String.Empty;
                fanLabel.Text = String.Empty;
            }

            UpdateColumnVisibility();

            //may not be hashing yet
            if (poolInformation != null)
                poolInformationResponseBindingSource.DataSource = poolInformation;
            else
                poolInformationResponseBindingSource.DataSource = new PoolInformationResponse();
        }
Exemple #5
0
        private void NotifyCoinToMine(CoinInformation coin)
        {
            string value = coin.AverageProfitability.ToString(".#") + "%";
            string noun = "average profitability";

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

            string infoUrl = coinApiContext.GetInfoUrl();

            notificationsControl.AddNotification(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));
                    }, infoUrl);
        }
Exemple #6
0
        private void PopulateCoinStatsForListViewItem(CoinInformation coinInfo, ListViewItem item)
        {
            deviceListView.BeginUpdate();
            try
            {
                item.SubItems["Difficulty"].Tag = coinInfo.Difficulty;
                item.SubItems["Difficulty"].Text = coinInfo.Difficulty.ToDifficultyString();

                string unit = "BTC";

                item.SubItems["Price"].Text = String.Format("{0} {1}", coinInfo.Price.ToFriendlyString(), unit);

                if (miningEngine.Donating && perksConfiguration.ShowExchangeRates
                    //ensure Coinbase is available:
                    && (sellPrices != null)
                    //ensure coin API is available:
                    && (coinInfo != null))
                {
                    double btcExchangeRate = sellPrices.Subtotal.Amount;
                    double coinExchangeRate = 0.00;

                    coinExchangeRate = coinInfo.Price * btcExchangeRate;

                    item.SubItems["Exchange"].Tag = coinExchangeRate;
                    item.SubItems["Exchange"].Text = String.Format("${0}", coinExchangeRate.ToFriendlyString(true));
                }

                switch (engineConfiguration.StrategyConfiguration.ProfitabilityKind)
                {
                    case StrategyConfiguration.CoinProfitabilityKind.AdjustedProfitability:
                        item.SubItems["Profitability"].Text = Math.Round(coinInfo.AdjustedProfitability, 2) + "%";
                        break;
                    case StrategyConfiguration.CoinProfitabilityKind.AverageProfitability:
                        item.SubItems["Profitability"].Text = Math.Round(coinInfo.AverageProfitability, 2) + "%";
                        break;
                    case StrategyConfiguration.CoinProfitabilityKind.StraightProfitability:
                        item.SubItems["Profitability"].Text = Math.Round(coinInfo.Profitability, 2) + "%";
                        break;
                }
            }
            finally
            {
                deviceListView.EndUpdate();
            }
        }
Exemple #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;
 }