public void Add(Coin newCoin)
        {
            bool found = false;
            foreach (Coin c in ListOfCoins)
            {
                if (c.TagName == newCoin.TagName && c.Algo == newCoin.Algo && !newCoin.IsMultiPool)
                {
                    if (c.Height < newCoin.Height)
                    {
                        ListOfCoins.Remove(c);
                    }
                    else
                    {
                        found = true;
                    }

                    break;
                }
            }

            if (!found && UsedInProfile(newCoin.Algo, UsedProfile.CustomAlgoList))
            {
                ListOfCoins.Add(newCoin);
            }
        }
        private Color GetRowColor(Coin coin)
        {
            if (!coin.HasImplementedMarketApi)
            {
                return Color.Plum;
            }

            if (coin.Exchanges.Count(exchange => exchange.IsFrozen) != 0)
            {
                return Color.DeepSkyBlue;
            }

            if (coin.BtcPerDay <= 0)
            {
                return coin.IsMultiPool ? Color.OrangeRed : Color.Red;
            }

            if (coin.IsMultiPool)
            {
                return Color.YellowGreen;
            }

            if (coin.TotalExchange.BtcVolume == 0)
            {
                return Color.BurlyWood;
            }

            if (coin.TotalExchange.BtcVolume < coin.BtcPerDay)
            {
                return Color.PaleTurquoise;
            }

            return Color.GreenYellow;
        }
        public DetailedResult(Coin usedCoin)
        {
            InitializeComponent();
            _usedCoin = usedCoin;

            Text = "[" + _usedCoin.TagName + "] " + _usedCoin.FullName + " - Detailed results";

            FillGeneralInfo();
            FillMarketInfo();
        }
        public void UpdateCoinWarz(string apiKey)
        {
            CoinWarz cwzData = JsonControl.DownloadSerializedApi<CoinWarz>(
                _client.GetStreamAsync("http://www.coinwarz.com/v1/api/profitability/?algo=all&apikey=" + apiKey).Result);

            if (cwzData.Success)
            {
                foreach (CoinWarz.Coin cwzCoin in cwzData.Data)
                {
                    Coin c = new Coin(cwzCoin);
                    c.Algo = GetCleanedAlgo(c.Algo);
                    Add(c);
                }
            }
            else
            {
                throw new Exception(cwzData.Message);
            }
        }
        public void UpdateCoinTweak(string apiKey)
        {
            CoinTweak ctwData = JsonControl.DownloadSerializedApi<CoinTweak>(
                _client.GetStreamAsync("http://cointweak.com/API/getProfitOverview/&key=" + apiKey).Result);

            if (ctwData.Success)
            {
                foreach (CoinTweak.Coin ctwCoin in ctwData.Coins)
                {
                    Coin c = new Coin(ctwCoin);
                    if (c.TagName == "RUBY")
                    {
                        c.TagName = "RBY";
                    }
                    c.Algo = GetCleanedAlgo(c.Algo);

                    Add(c);
                }
            }
            else
            {
                throw new Exception(ctwData.CallsRemaining.ToString(CultureInfo.InvariantCulture) + " calls remaining or invalid API key");
            }
        }
 public void UpdateWhatToMine()
 {
     WhatToMine wtmData = JsonControl.DownloadSerializedApi<WhatToMine>(_client.GetStreamAsync("http://www.whattomine.com/coins.json").Result);
     foreach (KeyValuePair<string, WhatToMine.Coin> wtmCoin in wtmData.Coins)
     {
         Coin c = new Coin(wtmCoin);
         c.Algo = GetCleanedAlgo(c.Algo);
         Add(c);
     }
 }
        public void UpdateCrypToday(decimal average)
        {
            CrypToday ct = JsonControl.DownloadSerializedApi<CrypToday>(
                _client.GetStreamAsync("http://cryp.today/data").Result);
            Coin[] tempMultipools = new Coin[ct.Cols.Count-1];

            Parallel.For(0, ct.Cols.Count - 1, _po, i =>
            {
                string[] splitNameAndAlgo = ct.Cols[i + 1].Label.Split(' ');
                tempMultipools[i] = new Coin();
                switch (splitNameAndAlgo[1])
                {
                    case "X11":
                    case "X13":
                        tempMultipools[i].Algo = splitNameAndAlgo[1];
                        break;
                    case "N":
                        tempMultipools[i].Algo = "SCRYPTN";
                        break;
                    //case "S":
                    default:
                        tempMultipools[i].Algo = "SCRYPT";
                        break;
                }

                tempMultipools[i].FullName = ct.Cols[i + 1].Label + " (CT)";
                tempMultipools[i].TagName = "CT" + i + tempMultipools[i].Algo;

                tempMultipools[i].HasImplementedMarketApi = true;
                tempMultipools[i].IsMultiPool = true;

                Coin.Exchange ctExchange = new Coin.Exchange {ExchangeName = splitNameAndAlgo[0]};
                tempMultipools[i].Exchanges.Add(ctExchange);
            });

            for (int i = ct.Rows.Count - 1; i >= ct.Rows.Count - average; i--)
            {
                int row = i;
                Parallel.For(1, ct.Rows[i].Results.Count, _po, column =>
                {
                    double priceHolder;
                    if (!string.IsNullOrWhiteSpace(ct.Rows[row].Results[column].Btc) &&
                        double.TryParse(ct.Rows[row].Results[column].Btc, NumberStyles.Float,
                            CultureInfo.InvariantCulture, out priceHolder))
                    {
                        tempMultipools[column - 1].Exchanges[0].BtcPrice += priceHolder;
                        // Temp storing amount of not-null BtcPerDays into BlockReward
                        tempMultipools[column - 1].BlockReward++;
                    }
                });
            }

            foreach (Coin c in tempMultipools)
            {
                switch (c.Algo)
                {
                    case "X11":
                        c.Exchanges[0].BtcPrice /= 5.2;
                        break;
                    case "X13":
                        c.Exchanges[0].BtcPrice /= 3;
                        break;
                    case "SCRYPTN":
                        c.Exchanges[0].BtcPrice /= 0.47;
                        break;
                }

                c.Exchanges[0].BtcPrice /= c.BlockReward;
                c.Exchanges[0].BtcPrice *= 1000;
                c.BlockReward = 0;

                c.Source = "Cryp.Today";
                c.Retrieved = DateTime.Now;

                Add(c);
            }
        }
        private void AddPoolPickerPool(PoolPicker.Pool pool, List<PoolPicker.Pool.Algo> profitList, string algo, 
            DateTime whenToEnd, bool reviewCalc, double reviewPercentage)
        {
            Coin c = new Coin
            {
                HasImplementedMarketApi = true,
                IsMultiPool = true,
            };
            Coin.Exchange ppExchange = new Coin.Exchange { ExchangeName = pool.Name, };
            c.Exchanges.Add(ppExchange);

            c.Algo = algo;
            c.FullName = pool.Name + " " + c.Algo + " (PP)";
            c.TagName = "PP" + pool.Id + c.Algo;

            double dAverage = 0;
            int iCounter;
            for (iCounter = 0; iCounter < profitList.Count; iCounter++)
            {
                PoolPicker.Pool.Algo profit = profitList[iCounter];
                DateTime profitDate = DateTime.ParseExact(profit.Date, "yyyy-MM-dd",
                    CultureInfo.InvariantCulture);

                if (profitDate.Date < whenToEnd.Date)
                {
                    break;
                }

                dAverage += profit.Btc;
                
                if (profitDate.Date.Equals(whenToEnd.Date)) break;
            }

            c.Exchanges[0].BtcPrice = 
                c.Algo == "KECCAK" || c.Algo == "SHA256"
                ? dAverage/(iCounter + 1)
                : dAverage/(iCounter + 1)*1000;

            if (reviewCalc)
            {
                c.Exchanges[0].BtcPrice *= reviewPercentage;
            }

            c.Source = "PoolPicker.eu";
            c.Retrieved = DateTime.Now;

            Add(c);
        }
        private void UpdateCryptoine(Coin.Exchange exchange)
        {
            chkCryptoineBtc.Checked = _useBtc;
            lblCryptoineDepth.Text = "Depth: " + _depth + " orders";
            trackCryptoineDepth.Value = _depth;
            lblCryptoineBox.Text = "Box percentage: " + _boxPercentage + "% - " + (100 - _boxPercentage) + "%";
            trackCryptoineBox.Value = _boxPercentage;
            lblCryptoineWhisker.Text = "Whisker percentage: " + _whiskerPercentage + "% - " + (100 - _whiskerPercentage) + "%";
            trackCryptoineWhisker.Value = _whiskerPercentage;

            double[] yBuyValues = GetBoxPlotValues(_boxPercentage, _whiskerPercentage, _depth,
                exchange.BuyOrders, _useBtc);
            chartCryptoineBuy.Series["BoxPlotSeries"].Points.Clear();
            chartCryptoineBuy.Series["BoxPlotSeries"].Points.Add(yBuyValues);
            dgvCryptoineBuy.DataSource = exchange.BuyOrders;

            double[] ySellValues = GetBoxPlotValues(_boxPercentage, _whiskerPercentage, _depth,
                exchange.SellOrders, _useBtc);
            chartCryptoineSell.Series["BoxPlotSeries"].Points.Clear();
            chartCryptoineSell.Series["BoxPlotSeries"].Points.Add(ySellValues);
            dgvCryptoineSell.DataSource = exchange.SellOrders;
        }
        private void InitMintPal(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabMintpal);

            txtMintpalFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtMintpalLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtMintpalDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtMintpalWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkMintpal.Text = "MintPal: " + _usedCoin.TagName + "/BTC";
            linkMintpal.Links[0] = new LinkLabel.Link(0, linkMintpal.Text.Length,
                "https://www.mintpal.com/market/" + _usedCoin.TagName + "/BTC");

            UpdateMintpal(exchange);
        }
        private void InitAtomic(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabAtomicTrade);

            txtAtomicFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtAtomicLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtAtomicDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtAtomicWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkAtomic.Text = "Atomic: " + _usedCoin.TagName + "/BTC";
            linkAtomic.Links[0] = new LinkLabel.Link(0, linkAtomic.Text.Length,
                "https://www.atomic-trade.com/markets");

            UpdateAtomic(exchange);
        }
        private void InitAllCoin(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabAllCoin);

            txtAllcoinFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtAllcoinLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtAllcoinDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtAllcoinWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkAllcoin.Text = "Allcoin: " + _usedCoin.TagName + "/BTC";
            linkAllcoin.Links[0] = new LinkLabel.Link(0, linkAllcoin.Text.Length,
                "https://www.allcoin.com/trade/" + _usedCoin.TagName + "_BTC");

            UpdateAllcoin(exchange);
        }
        private void InitAllCrypt(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabAllCrypt);

            txtAllcryptFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtAllcryptLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtAllcryptDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtAllcryptWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkAllcrypt.Text = "Allcrypt: " + _usedCoin.TagName + "/BTC";
            linkAllcrypt.Links[0] = new LinkLabel.Link(0, linkAllcrypt.Text.Length,
                "https://www.google.com/search?q=allcrypt+" + _usedCoin.TagName + "+btc&btnI=&gws_rd=ssl");

            UpdateAllCrypt(exchange);
        }
        private void InitCCex(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabCCex);

            txtCcexFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtCcexLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtCcexDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtCcexWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkCcex.Text = "C-Cex: " + _usedCoin.TagName + "/BTC";
            linkCcex.Links[0] = new LinkLabel.Link(0, linkCcex.Text.Length,
                "https://c-cex.com/?p=" + _usedCoin.TagName.ToLowerInvariant() + "-btc");

            UpdateCCex(exchange);
        }
        private void InitBTer(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabBTer);

            txtBterFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtBterLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtBterDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtBterWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkBter.Text = "BTer: " + _usedCoin.TagName + "/BTC";
            linkBter.Links[0] = new LinkLabel.Link(0, linkBter.Text.Length,
                "https://bter.com/trade/" + _usedCoin.TagName.ToLowerInvariant() + "_btc");

            UpdateBTer(exchange);
        }
        private void InitCryptoine(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabCryptoine);

            txtCryptoineFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtCryptoineLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " + _usedCoin.TagName;
            txtCryptoineDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtCryptoineWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkCryptoine.Text = "Cryptoine: " + _usedCoin.TagName + "/BTC";
            linkCryptoine.Links[0] = new LinkLabel.Link(0, linkCryptoine.Text.Length,
                "https://cryptoine.com/trade/" + _usedCoin.TagName.ToLowerInvariant() + "_btc");

            UpdateCryptoine(exchange);
        }
        private void InitBittrex(Coin.Exchange exchange)
        {
            tbcMarkets.TabPages.Add(tabBittrex);

            txtBittrexFallthrough.Text = exchange.FallThroughPrice.ToString("0.00000000") + " BTC";
            txtBittrexLeftover.Text = exchange.LeftOverInFallThrough.ToString("0.########") + " " +_usedCoin.TagName;
            txtBittrexDailyvolume.Text = exchange.BtcVolume.ToString("0.####") + " BTC";
            txtBittrexWeight.Text = (exchange.Weight * 100).ToString("0.##") + "%";

            linkBittrex.Text = "Bittrex: " + _usedCoin.TagName + "/BTC";
            linkBittrex.Links[0] = new LinkLabel.Link(0, linkBittrex.Text.Length, 
                "https://bittrex.com/Market/Index?MarketName=BTC-" + _usedCoin.TagName);

            UpdateBittrex(exchange);
        }