Esempio n. 1
0
        private List <CoinInformation> GetFilteredProfitableCoins(IEnumerable <CoinInformation> unfilteredProfitableCoins)
        {
            List <CoinInformation> filteredProfitableCoins = unfilteredProfitableCoins.ToList(); //call ToList to get a copy

            if (!string.IsNullOrEmpty(engineConfiguration.StrategyConfiguration.MinimumProfitabilitySymbol))
            {
                CoinInformation minimumCoin = filteredProfitableCoins.SingleOrDefault(c => c.Symbol.Equals(engineConfiguration.StrategyConfiguration.MinimumProfitabilitySymbol));
                int             index       = filteredProfitableCoins.IndexOf(minimumCoin);
                index++;
                filteredProfitableCoins.RemoveRange(index, filteredProfitableCoins.Count - index);
            }

            if (engineConfiguration.StrategyConfiguration.MinimumProfitabilityPercentage.HasValue)
            {
                double minimumValue = engineConfiguration.StrategyConfiguration.MinimumProfitabilityPercentage.Value;

                switch (engineConfiguration.StrategyConfiguration.ProfitabilityBasis)
                {
                case Configuration.StrategyConfiguration.CoinProfitabilityBasis.AdjustedProfitability:
                    filteredProfitableCoins = filteredProfitableCoins.Where(c => c.AdjustedProfitability > minimumValue).ToList();
                    break;

                case Configuration.StrategyConfiguration.CoinProfitabilityBasis.AverageProfitability:
                    filteredProfitableCoins = filteredProfitableCoins.Where(c => c.AverageProfitability > minimumValue).ToList();
                    break;

                case Configuration.StrategyConfiguration.CoinProfitabilityBasis.StraightProfitability:
                    filteredProfitableCoins = filteredProfitableCoins.Where(c => c.Profitability > minimumValue).ToList();
                    break;
                }
            }

            return(filteredProfitableCoins);
        }
        /// <summary>
        /// Get a Coin from a transaction
        /// </summary>
        /// <param name="transaction">New Transaction object</param>
        /// <returns>CoinInformation object</returns>
        private CoinInformation GetCoin(Contracts.CryptoBits.NewTransaction transaction)
        {
            CoinInformation thisCoin = this.coinInfoList.Where(c => c.symbol == transaction.symbol).FirstOrDefault();

            if (thisCoin == null)
            {
                thisCoin = this.CreateCoin(transaction);
            }
            else
            {
                Wallet wallet = GetWallet(transaction, thisCoin);
                if (wallet == null && transaction.transactionType == TransactionType.BUY)
                {
                    var buyList   = CreateCoinBuyList(transaction);
                    var newWallet = this.CreateCoinWallet(transaction, buyList);
                }
                else if (transaction.transactionType == TransactionType.BUY)
                {
                    var coinBuy = CreateCoinBuy(transaction);

                    wallet.coinBuyList.Add(coinBuy);
                }
                else if (transaction.transactionType == TransactionType.SELL)
                {
                    var buyList = wallet.coinBuyList;

                    wallet.coinBuyList = SellCoins(buyList, transaction);
                }
            }

            return(thisCoin);
        }
Esempio n. 3
0
        private void logProcessClose(MinerProcess minerProcess)
        {
            DateTime startDate = minerProcess.StartDate;
            DateTime endDate   = DateTime.Now;
            string   coinName  = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol   = String.Empty;

            //coin may not be in CoinChoose.com
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol   = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));

            if (coinInfo != null)
            {
                priceAtEnd = coinInfo.Price;
            }

            List <int> deviceIndexes = minerProcess.MinerConfiguration.DeviceIndexes;

            logProcessClose(startDate, endDate, coinName, coinSymbol, priceAtStart, priceAtEnd, deviceIndexes);
        }
Esempio n. 4
0
        /// <summary>
        /// Utility method: GetCoinSnapshotByID - Invoke CryptoCompare.com API's CoinSnapshotFullById call to
        /// obtain the additional elements (i.e. current blocks, block reward, total coins mined, etc.) that
        /// are not provided by CryptoCompare.com API's coinlist call, given the numeric id of a coin
        /// </summary>
        /// <param name="client"></param>
        /// <param name="coinInformation"></param>
        /// <returns>void</returns>
        private void GetCoinSnapshotByID(ApiWebClient client, CoinInformation coinInformation)
        {
            string coinSnapshotIDParam = "";

            // Obtain numeric id of the coin whose full record is passed in as coinInformation parameter
            coinSnapshotIDParam = coinInformation.Id;

            // Build URL string for the CoinSnapshotFullById CryptoCompare.com API call
            string apiUrl = BuildApiUrlByID(coinSnapshotIDParam, "CoinSnapshotByID");

            // Invoke CryptoCompare.com API's CoinSnapshotFullById call URL, then deserialize result and populate
            // the additional fields provided by this API call into the coinInformation coin record
            string json = client.DownloadAsString(apiUrl);

            try
            {
                RootObjectCoinSnapshot  coinsnapshotset = JsonConvert.DeserializeObject <RootObjectCoinSnapshot>(json);
                GeneralCoinSnapshotData coinSnapshot    = new GeneralCoinSnapshotData();
                coinSnapshot = coinsnapshotset.Data.General;
                coinInformation.PopulateFromJson(coinSnapshot);
            }
            catch (Exception e)
            {
                string errorMsg = e.Message;
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private List <Engine.Data.Configuration.Device> CreateAutomaticDeviceConfiguration(IEnumerable <CoinInformation> orderedCoinInformation)
        {
            //order by adjusted profitability
            List <CoinInformation> filteredCoinInformation = GetFilteredCoinInformation(orderedCoinInformation);

            //get sha256 only options
            List <CoinInformation> sha256ProfitableCoins = filteredCoinInformation.Where(c => c.Algorithm.Equals("SHA-256")).ToList();

            //ABM - always be mining
            if (filteredCoinInformation.Count == 0)
            {
                filteredCoinInformation.Add(orderedCoinInformation.First());
            }

            if (sha256ProfitableCoins.Count == 0)
            {
                CoinInformation sha256Info = orderedCoinInformation.Where(c => c.Algorithm.Equals("SHA-256")).FirstOrDefault();
                if (sha256Info != null)
                {
                    sha256ProfitableCoins.Add(sha256Info);
                }
            }
            //end ABM

            return(CreateDeviceConfigurationForProfitableCoins(filteredCoinInformation, sha256ProfitableCoins));
        }
Esempio n. 7
0
        private static void ApplyCoinInformationToViewModel(List <CoinInformation> coinInformationModels, string coinSymbol, DeviceViewModel deviceViewModel)
        {
            CoinInformation coinInformationModel = coinInformationModels.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));

            if (coinInformationModel != null)
            {
                ObjectCopier.CopyObject(coinInformationModel, deviceViewModel, "Name", "Exchange");
            }
        }
 // This overload of PopulateFromJson populates the additional elements of a single CoinInformation object,
 // as deserialized from CryptoCompare.com API's CoinSnapshotFullById call
 public static void PopulateFromJson(this CoinInformation coinInformation, GeneralCoinSnapshotData snapshot)
 {
     coinInformation.CurrentBlocks      = Convert.ToInt32(snapshot.BlockNumber);
     coinInformation.Reward             = Convert.ToDouble(snapshot.BlockReward);
     coinInformation.TotalCoinsMined    = snapshot.TotalCoinsMined;
     coinInformation.RewardReduction    = snapshot.BlockRewardReduction;
     coinInformation.EstimatedBlockTime = Convert.ToDouble(snapshot.BlockTime);
     coinInformation.NetworkHashRate    = Convert.ToDouble(snapshot.NetHashesPerSecond);
 }
Esempio n. 9
0
        public async Task <JsonResult> GetById(string id)
        {
            WebReq req      = new WebReq();
            string response = await req.InfoById(id);

            CoinInformation ci = JsonConvert.DeserializeObject <CoinInformation>(response);

            ci.Description = Regex.Replace(ci.Description, @"\t|\n|\r", "");
            return(Json(ci));
        }
Esempio n. 10
0
        private void DoLogProcessClose(MinerProcess minerProcess)
        {
            if (LogProcessClose == null)
            {
                return;
            }

            DateTime startDate = minerProcess.StartDate;
            DateTime endDate   = DateTime.Now;
            string   coinName  = minerProcess.MinerConfiguration.CoinName;

            double priceAtStart = 0;
            string coinSymbol   = String.Empty;

            //coin may not be in Coin API
            if (minerProcess.CoinInformation != null)
            {
                coinSymbol   = minerProcess.CoinInformation.Symbol;
                priceAtStart = minerProcess.CoinInformation.Price;
            }

            double priceAtEnd = priceAtStart;

            //can't use Single here - coin info may be gone now and we crash
            CoinInformation coinInfo = null;

            if (coinInformation != null) //null if no internet connection
            {
                coinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            }
            if (coinInfo != null)
            {
                priceAtEnd = coinInfo.Price;
            }

            //get a copy using ToList() so we can change the list in the event handler without
            //affecting relaunching processes
            List <DeviceDescriptor> deviceDescriptors = minerProcess.MinerConfiguration.DeviceDescriptors.ToList();

            LogProcessCloseArgs args = new LogProcessCloseArgs
            {
                StartDate          = startDate,
                EndDate            = endDate,
                CoinName           = coinName,
                CoinSymbol         = coinSymbol,
                StartPrice         = priceAtStart,
                EndPrice           = priceAtEnd,
                DeviceDescriptors  = deviceDescriptors,
                MinerConfiguration = minerProcess.MinerConfiguration,
                AcceptedShares     = minerProcess.AcceptedShares
            };

            LogProcessClose(this, args);
        }
Esempio n. 11
0
        private static void CalculateProfitability(List <CoinInformation> coinInformation)
        {
            CoinInformation btcInformation = coinInformation.Single(mpi => mpi.Symbol.Equals("BTC", StringComparison.OrdinalIgnoreCase));

            foreach (CoinInformation otherInformation in coinInformation)
            {
                otherInformation.Profitability         = (otherInformation.Income / btcInformation.Income) * 100;
                otherInformation.AdjustedProfitability = otherInformation.Profitability;
                otherInformation.AverageProfitability  = otherInformation.Profitability;
            }
        }
Esempio n. 12
0
        public void GetCoinInformation_BitcoinBasis_IsBasedOnBitcoin()
        {
            //act
            List <CoinInformation> coinInformation = new ApiContext().GetCoinInformation().ToList();

            //assert
            CoinInformation coin = coinInformation.Single(c => c.Symbol.Equals("BTC"));

            Assert.AreEqual(coin.Profitability, 100);
            coin = coinInformation.Single(c => c.Symbol.Equals("LTC"));
            Assert.AreNotEqual(coin.Profitability, 100);
        }
Esempio n. 13
0
        private static List <CoinInformation> CopyCoinInformation(List <CoinInformation> coinInformation)
        {
            List <CoinInformation> coinInformationCopy = new List <CoinInformation>();

            foreach (CoinInformation realCoin in coinInformation)
            {
                CoinInformation coinCopy = new CoinInformation();
                ObjectCopier.CopyObject(realCoin, coinCopy);
                coinInformationCopy.Add(coinCopy);
            }
            return(coinInformationCopy);
        }
Esempio n. 14
0
        static int Lookup(string szSelectedCoin, decimal hashrate, bool bIncomeInBTC, long interval, string exchange, RegistrySettings rs)
        {
            Profitability       p   = new Profitability();
            CoinInformation     ci  = new CoinInformation();
            ExchangeInformation ei  = new ExchangeInformation();
            CoinInfo            inf = rs.Coins[szSelectedCoin];
            double diff             = 0;

            try { diff = ci.GetDifficulty(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); }
            catch { Console.WriteLine("Unable to fetch difficulty"); return(-1); }
            decimal reward = 0;

            try { reward = ci.GetReward(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); }
            catch { Console.WriteLine("Unable to fetch reward"); return(-1); }
            if (hashrate == 0)
            {
                switch (inf.DefaultHashRateUnit)
                {
                case "H/s":
                    hashrate = Convert.ToDecimal(inf.DefaultHashRate);
                    break;

                case "kH/s":
                    hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000;
                    break;

                case "MH/s":
                    hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000000;
                    break;

                case "GH/s":
                    hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 100000000;
                    break;

                default:
                    throw new ArgumentException("invalid hashrate unit");
                }
            }
            if (!bIncomeInBTC)
            {
                Console.WriteLine(p.ProfitOnInterval(interval, hashrate, reward, (decimal)diff).ToString("F8"));
            }
            else
            {
                decimal exchrate = 0;
                try { exchrate = (szSelectedCoin.ToLower() != "bitcoin") ? ei.GetExchangeRate((exchange != "") ? exchange : inf.Exchange, inf.Abbreviation) : 1; }
                catch { Console.WriteLine("Unable to fetch exchange rate"); return(-1); }
                Console.WriteLine(p.ProfitOnIntervalBTC(interval, hashrate, reward, (decimal)diff, exchrate).ToString("F8"));
            }
            return(0);
        }
Esempio n. 15
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);
        }
        /// <summary>
        /// Create a coin from a transaction
        /// </summary>
        /// <param name="transaction">NewTransaction object</param>
        /// <returns>CoinInformation object</returns>
        private CoinInformation CreateCoin(NewTransaction transaction)
        {
            var newCoin    = new CoinInformation();
            var buys       = this.CreateCoinBuyList(transaction);
            var walletList = new List <Wallet>();

            walletList.Add(this.CreateCoinWallet(transaction, buys));

            newCoin.name       = transaction.name;
            newCoin.symbol     = transaction.symbol;
            newCoin.walletList = walletList;

            return(newCoin);
        }
Esempio n. 17
0
        private void setupProcessStartInfo(MinerProcess minerProcess)
        {
            string          coinName        = minerProcess.MinerConfiguration.CoinName;
            string          coinSymbol      = engineConfiguration.CoinConfigurations.Single(c => c.Coin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase)).Coin.Symbol;
            CoinInformation processCoinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));

            //coin may not be in CoinChoose.com
            if (coinInformation != null)
            {
                minerProcess.CoinInformation = processCoinInfo;
            }

            minerProcess.StartDate = DateTime.Now;
        }
 // This overload of PopulateFromJson populates the Price element of a single
 // CoinInformation object, as deserialized from CryptoCompare.com API's pricemulti call
 // This overload is not currently used
 public static void PopulateFromJson(this CoinInformation coinInformation, string priceStr)
 {
     try
     {
         coinInformation.Price = Convert.ToDouble(priceStr);
     }
     catch (FormatException e)
     {
         coinInformation.Price = 0.0;
     }
     catch (OverflowException e)
     {
         coinInformation.Price = 0.0;
     }
 }
        /// <summary>
        /// Get a wallet from a transaction
        /// </summary>
        /// <param name="transaction">NewTransaction object</param>
        /// <param name="thisCoin">CoinInformation object</param>
        /// <returns>Wallet object</returns>
        private static Wallet GetWallet(NewTransaction transaction, CoinInformation thisCoin)
        {
            Wallet thisWallet = null;

            if (transaction.sourceLocation == Location.Address)
            {
                thisWallet = thisCoin.walletList.Where(w => w.location == transaction.sourceLocation &&
                                                       w.address.addressId == transaction.sourceAddress.addressId).FirstOrDefault();
            }
            else
            {
                thisWallet = thisCoin.walletList.Where(w => w.location == transaction.sourceLocation).FirstOrDefault();
            }

            return(thisWallet);
        }
 // This overload of PopulateFromJson populates the basic elements of a single CoinInformation object,
 // as deserialized from CryptoCompare.com API's coinlist call
 public static void PopulateFromJson(this CoinInformation coinInformation, CoinInfo coin)
 {
     coinInformation.Id                  = coin.Id;
     coinInformation.Symbol              = coin.Name;
     coinInformation.Algorithm           = coin.Algorithm;
     coinInformation.CoinName            = coin.CoinName;
     coinInformation.FullName            = coin.FullName;
     coinInformation.FullyPremined       = coin.FullyPremined;
     coinInformation.ImageUrl            = coin.ImageUrl;
     coinInformation.PreMinedValue       = coin.PreMinedValue;
     coinInformation.ProofType           = coin.ProofType;
     coinInformation.SortOrder           = coin.SortOrder;
     coinInformation.TotalCoinsFreeFloat = coin.TotalCoinsFreeFloat;
     coinInformation.TotalCoinSupply     = coin.TotalCoinSupply;
     coinInformation.Url                 = coin.Url;
 }
Esempio n. 21
0
        //filter the coin information list by MinimumThresholdValue and MinimumThresholdSymbol
        private List <CoinInformation> GetFilteredCoinInformation(IEnumerable <CoinInformation> unfilteredCoinInformation)
        {
            List <CoinInformation> filteredCoinInformation = unfilteredCoinInformation.ToList(); //call ToList to get a copy

            if (!string.IsNullOrEmpty(engineConfiguration.StrategyConfiguration.MinimumThresholdSymbol))
            {
                CoinInformation minimumCoin = filteredCoinInformation.SingleOrDefault(c => c.Symbol.Equals(engineConfiguration.StrategyConfiguration.MinimumThresholdSymbol));
                int             index       = filteredCoinInformation.IndexOf(minimumCoin);
                index++;
                filteredCoinInformation.RemoveRange(index, filteredCoinInformation.Count - index);
            }

            if (engineConfiguration.StrategyConfiguration.MinimumThresholdValue.HasValue)
            {
                double minimumValue = engineConfiguration.StrategyConfiguration.MinimumThresholdValue.Value;

                switch (engineConfiguration.StrategyConfiguration.MiningBasis)
                {
                case Strategy.CoinMiningBasis.Profitability:
                    switch (engineConfiguration.StrategyConfiguration.ProfitabilityKind)
                    {
                    case Strategy.CoinProfitabilityKind.AdjustedProfitability:
                        filteredCoinInformation = filteredCoinInformation.Where(c => c.AdjustedProfitability > minimumValue).ToList();
                        break;

                    case Strategy.CoinProfitabilityKind.AverageProfitability:
                        filteredCoinInformation = filteredCoinInformation.Where(c => c.AverageProfitability > minimumValue).ToList();
                        break;

                    case Strategy.CoinProfitabilityKind.StraightProfitability:
                        filteredCoinInformation = filteredCoinInformation.Where(c => c.Profitability > minimumValue).ToList();
                        break;
                    }
                    break;

                case Strategy.CoinMiningBasis.Difficulty:
                    filteredCoinInformation = filteredCoinInformation.Where(c => c.Difficulty < minimumValue).ToList();
                    break;

                case Strategy.CoinMiningBasis.Price:
                    filteredCoinInformation = filteredCoinInformation.Where(c => c.Price > minimumValue).ToList();
                    break;
                }
            }

            return(filteredCoinInformation);
        }
 // This overload of PopulateFromJson populates the Price and Market Cap elements of a single
 // CoinInformation object, as deserialized from CryptoCompare.com API's pricemulti call
 public static void PopulateFromJson(this CoinInformation coinInformation, CoinPrice priceRec)
 {
     try
     {
         coinInformation.Price     = priceRec.USD;
         coinInformation.MarketCap = Convert.ToDouble(coinInformation.TotalCoinsMined) * coinInformation.Price;
     }
     catch (FormatException e)
     {
         coinInformation.Price     = 0.0;
         coinInformation.MarketCap = 0.0;
     }
     catch (OverflowException e)
     {
         coinInformation.Price     = 0.0;
         coinInformation.MarketCap = 0.0;
     }
 }
Esempio n. 23
0
        // load data into form

        private void cbCoinType_SelectedIndexChanged(object sender, EventArgs e)
        {
            ExchangeInformation ei = new ExchangeInformation();
            CoinInformation     ci = new CoinInformation();

            lblUpdating.Visible = true;
            this.Refresh();
            string   szCoinType = cbCoinType.Items[cbCoinType.SelectedIndex].ToString();
            CoinInfo i          = rs.Coins[szCoinType];

            lblAbbrev.Text = lblRewardCurrency.Text = i.Abbreviation;
            lblExchangeRateCurrency.Text = "BTC/" + i.Abbreviation;
            try { tbDifficulty.Text = ci.GetDifficulty(i.ExplorerType, i.ExplorerBaseURL, i.ExplorerChain, i.Abbreviation).ToString(); }
            catch { tbDifficulty.Text = "Unavailable"; }
            try { tbReward.Text = ci.GetReward(i.ExplorerType, i.ExplorerBaseURL, i.ExplorerChain, i.Abbreviation).ToString(); }
            catch { tbReward.Text = "Unavailable"; }
            for (int c = 0; c < cbHashrateUnit.Items.Count; c++)
            {
                if (((Item)cbHashrateUnit.Items[c]).Name == i.DefaultHashRateUnit)
                {
                    cbHashrateUnit.SelectedIndex = c;
                }
            }
            try
            {
                if (i.Exchange != null)
                {
                    tbExchangeRate.Text = ei.GetExchangeRate(i.Exchange, i.Abbreviation).ToString();
                }
                else
                {
                    tbExchangeRate.Text = "";
                }
            }
            catch { tbExchangeRate.Text = "Unavailable"; }
            if (cbCoinType.Items[cbCoinType.SelectedIndex].ToString().ToLower() == "bitcoin") // case-insensitive for Mono compatibility
            {
                tbExchangeRate.Text = "1";
            }
            tbHashrate.Text     = i.DefaultHashRate;
            lblUpdating.Visible = false;
            this.Refresh();
            OnChanged();
        }
Esempio n. 24
0
        private void setupProcessStartInfo(MinerProcess minerProcess)
        {
            string coinName   = minerProcess.MinerConfiguration.CoinName;
            string coinSymbol = engineConfiguration.CoinConfigurations.Single(c => c.CryptoCoin.Name.Equals(coinName, StringComparison.OrdinalIgnoreCase)).CryptoCoin.Symbol;

            CoinInformation processCoinInfo = null;

            if (coinInformation != null) //null if no network connection
            {
                processCoinInfo = coinInformation.SingleOrDefault(c => c.Symbol.Equals(coinSymbol, StringComparison.OrdinalIgnoreCase));
            }

            //coin may not be in Coin API
            if (processCoinInfo != null)
            {
                minerProcess.CoinInformation = processCoinInfo;
            }

            minerProcess.StartDate = DateTime.Now;
        }
Esempio n. 25
0
        // не активно по многим причинам
        //public async Task<int> MaxValueCrypto()
        //{
        //    List<string> cryptos = new List<string>();
        //    using var client = new HttpClient();
        //    string content = await client.GetStringAsync("https://*****:*****@$ "Название: {info.Name}
Новая? - {isnew}
Активная? - {isactive}
Ранг: {info.Rank}
Описание: {info.Description}"
            ;

            return(CoinInformation);
        }
Esempio n. 26
0
        /// <summary>
        /// Utility method: GetCoinPriceMulti - populates Price and Market Cap fields for result set of coin
        /// records; the coin symbols in the result set are passed in as parameters
        /// Note: if GetCoinPriceMulti method is being invoked from GetCoinInformation API method, Market Cap
        /// will always be 0 - see comment in GetCoinInformation method; only when GetCoinPriceMulti method is
        /// invoked from GetCoinInformationWithSnapshot, can the Market Cap be calculated
        /// </summary>
        /// <param name="client"></param>
        /// <param name="apiUrlInputParams"></param>
        /// <returns>void</returns>
        private void GetCoinPriceMulti(ApiWebClient client, string apiUrlInputParams)
        {
            // Build URL string for the Pricemulti CryptoCompare.com API call
            string apiUrl = BuildApiUrlWithBasicParams(apiUrlInputParams, "Pricemulti", true, true);

            // Invoke CryptoCompare.com API's pricemulti call URL, then deserialize result
            // JSON string will be in the following format: {"ETH":{"USD":226.63},"DASH":{"USD":187.87}}
            string json = client.DownloadAsString(apiUrl);

            // Reformat returned JSON string into format that can be deserialized into RootObjectPriceMulti object
            // Also make a copy of the returned JSON string, strip off leading "{" &  final "}", and split it into
            // an array of Price results per coin
            string remainingJson = json.Remove(0, 1);

            remainingJson = remainingJson.Remove(remainingJson.Length - 1, 1);
            json          = "{\"Data\":" + json;
            json         += "}";
            var coinpricelist = JsonConvert.DeserializeObject <RootObjectPriceMulti>(json);

            string[] splitJson = remainingJson.Split(',');

            int splitIndex = 0;

            // Loop through the Price results array, incrementing splitIndex as the loop iteration counter
            foreach (CoinPrice coinPrice in coinpricelist.Data.Values)
            {
                CoinInformation coinInformation = new CoinInformation();

                // For each array element (i.e. each coin's Price result), the coin symbol is the portion before
                // the first ":", minus the leading & final "\" that appear in the string as escape characters
                string fromCoin = splitJson[splitIndex].Split(':')[0];
                fromCoin = fromCoin.Trim('\"');

                // Select the coin being processed by current iteration of the for loop in the original coin
                // information result set and populate the Price and Market Cap fields in this coin's record
                coinInformation = _coinInfoResultSet.Find(x => x.Symbol.Equals(fromCoin));
                coinInformation.PopulateFromJson(coinPrice);

                splitIndex += 1;
            }
        }
Esempio n. 27
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);
        }
        public static void PopulateFromJson(this CoinInformation coinInformation, Data.ApiCoinInformation apiCoinInformation)
        {
            coinInformation.Symbol                = FixSymbolName(apiCoinInformation.Tag, apiCoinInformation.Algorithm);
            coinInformation.Algorithm             = FixAlgorithmName(apiCoinInformation.Algorithm);
            coinInformation.CurrentBlocks         = apiCoinInformation.Last_Block;
            coinInformation.Difficulty            = apiCoinInformation.Difficulty;
            coinInformation.Reward                = apiCoinInformation.Block_Reward;
            coinInformation.NetworkHashRate       = apiCoinInformation.Nethash;
            coinInformation.Profitability         = apiCoinInformation.Profitability;
            coinInformation.AdjustedProfitability = apiCoinInformation.Profitability;
            coinInformation.AverageProfitability  = apiCoinInformation.Profitability24;
            coinInformation.NetworkHashRate       = apiCoinInformation.Nethash;

            if (coinInformation.Symbol.Equals("BTC", StringComparison.OrdinalIgnoreCase))
            {
                coinInformation.Price = 1;
            }
            else
            {
                coinInformation.Price = apiCoinInformation.Exchange_Rate;
            }
        }
Esempio n. 29
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);
        }
Esempio n. 30
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);
        }