Example #1
0
        //LOGIC BEHIND ALLOCATING NEW STRING FOR INPUTTED CUSTOM COIN
        public void TestOptionCoins(ref string RealCoin, ref string RealCoinFN)
        {
            try
            {
                double counting = 0;

                Coins = JsonConvert.DeserializeObject <List <MarketCap> >(EaseMethods.API(@"https://api.coinmarketcap.com/v1/ticker/?start=0&limit=0"));
                if (RealCoin.ToUpper() == "BTC" || RealCoin.ToUpper() == "BITCOIN")
                {
                    RealCoin   = "BTC";
                    RealCoinFN = "bitcoin";
                }
                else if (RealCoin == "")
                {
                    RealCoin   = "";
                    RealCoinFN = "";
                }
                else
                {
                    foreach (var coin in Coins)
                    {
                        counting = counting + 1;
                        if (coin.name.ToUpper() == RealCoin.ToUpper())
                        {
                            RealCoin   = coin.symbol;
                            RealCoinFN = coin.id.ToLower();
                            break;
                        }
                        else if (coin.symbol == RealCoin.ToUpper())
                        {
                            RealCoin   = coin.symbol;
                            RealCoinFN = coin.id;
                            break;
                        }
                        else if (counting == 1545)      //MAX COINS IN API READER
                        {
                            RealCoin   = "";
                            RealCoinFN = "";
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Reference.CryptoForm.lblSync.Text    = "Coin Error";
                Reference.CryptoForm.lblSync.Visible = true;
            }
        }
Example #2
0
        //Main Function for getting data on any coin for the home page.
        public static void GETINFO(string CRYPTO, string customCoin, Label xCv, Label xBTCv, Label xUSDc, Label xUSD24c, Label xUSD7c, Label xUSDp, Label xUSD24p, Label xUSD7p, Label xC, Label xBTC, Label xTimev, GroupBox Number)
        {
            if (PublicCurrencyIndex == 0)       //0 is the index for USD.
            {
                CURRENCY = "USD";
            }
            else if (PublicCurrencyIndex == 1)      //1 is the index for AUD.
            {
                CURRENCY = "AUD";
            }

            if (CRYPTO == "" || customCoin == "")       //If the coin is empty set labels to NO DATA.
            {
                if (PublicCurrencyIndex == 0)
                {
                    xC.Text = "XXX/USD";
                }
                else if (PublicCurrencyIndex == 1)
                {
                    xC.Text = "XXX/AUD";
                }
                xBTC.Text    = "XXX/BTC";
                xCv.Text     = "No Data";
                xBTCv.Text   = "No Data";
                xUSDp.Text   = "No Data";
                xUSD24p.Text = "No Data";
                xUSD7p.Text  = "No Data";
                xUSDc.Text   = "";
                xUSD24c.Text = "";
                xUSD7c.Text  = "";
                Number.Text  = "      " + "XXX";
                xTimev.Text  = "No Data";

                //Reset Label Forcolor to Black.
                xCv.ForeColor     = Color.Black;
                xBTCv.ForeColor   = Color.Black;
                xUSDp.ForeColor   = Color.Black;
                xUSD24p.ForeColor = Color.Black;
                xUSD7p.ForeColor  = Color.Black;
            }
            else
            {
                //Deserialize API into jsonString.


                //Set CoinsDetailed to the new jsonString from above API.
                CoinsDetailed = JsonConvert.DeserializeObject <List <MarketCap> >(EaseMethods.API(@"https://api.coinmarketcap.com/v1/ticker/" + CRYPTO + @"/?convert=" + CURRENCY));

                //Default Labelling based on first data.
                xBTC.Text   = customCoin + "/BTC";
                Number.Text = "";
                Number.Text = "      " + customCoin;

                //Calculating Coin Price Against USD or AUD.
                if (PublicCurrencyIndex == 0)
                {
                    xC.Text = customCoin + "/USD";
                    foreach (var data in CoinsDetailed)             //Coin Against USD
                    {
                        string  price_usd;
                        string  percent;
                        decimal Dpercent = 0;
                        decimal newprice;
                        price_usd = data.price_usd;                   //Set varaible price usd to the value found from the CoinsDetailed data.
                        price_usd = EaseMethods.RemoveExtraText(price_usd);
                        newprice  = Convert.ToDecimal(price_usd);     //Converting to decimal for more accurate financial calculations.
                        if (CRYPTO == "bitcoin")
                        {
                            Crypto.UniversalBTCPrice = Convert.ToDouble(newprice); //Setting Universal BTC Price for Mining Page.
                        }
                        price_usd = string.Format("{0:#,0.00##}", newprice);       //Format the price to include commas and up to 4 decimal points.
                        price_usd = "$" + price_usd;
                        percent   = data.percent_change_1h;
                        CalculateCoinAgainstFiatPercentage(price_usd, percent, Dpercent, xCv);          //Checking if it is increasing or decreasing for the triangle arrow and forecolor.
                        break;
                    }
                }
                else if (PublicCurrencyIndex == 1)
                {
                    xC.Text = customCoin + "/AUD";
                    foreach (var data in CoinsDetailed)             //Coin Against AUD
                    {
                        string  price_aud;
                        string  percent;
                        decimal Dpercent = 0;
                        decimal newprice;
                        price_aud = data.price_aud;                          //Set varaible price usd to the value found from the CoinsDetailed data.
                        price_aud = EaseMethods.RemoveExtraText(price_aud);
                        newprice  = Convert.ToDecimal(price_aud);            //Converting to decimal for more accurate financial calculations.
                        price_aud = string.Format("{0:#,0.00##}", newprice); //Format the price to include commas and up to 4 decimal points.
                        price_aud = "$" + price_aud;
                        percent   = data.percent_change_1h;
                        CalculateCoinAgainstFiatPercentage(price_aud, percent, Dpercent, xCv);      //Checking if it is increasing or decreasing for the triangle arrow and forecolor.
                        break;
                    }
                }
                foreach (var data in CoinsDetailed)         //Calculate Last Updated Time.
                {
                    string Time;
                    string FinalTime;
                    double DTime;
                    Time  = data.last_updated;
                    Time  = EaseMethods.RemoveExtraText(Time);
                    DTime = Convert.ToDouble(Time);
                    DateTime UniversalTime = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(DTime);        //Converting UNIX time to DateTime.
                    DateTime LocalTime     = UniversalTime.ToLocalTime();                                   //Converting DateTime to LocatTime.
                    if (TimeZoneNumber == 0)
                    {
                        FinalTime   = UniversalTime.ToString("r");                  //'r' is a format of DateTime display.
                        FinalTime   = FinalTime.Substring(0, FinalTime.Length - 4); //Remove Extra Text Caused by 'r'.
                        xTimev.Text = FinalTime + " UTC";
                    }
                    else if (TimeZoneNumber == 1)
                    {
                        FinalTime   = LocalTime.ToString("r");                      //'r' is a format of DateTime display.
                        FinalTime   = FinalTime.Substring(0, FinalTime.Length - 4); //Remove Extra Text Caused by 'r'.
                        xTimev.Text = FinalTime + " LOCAL";
                    }
                    break;
                }
                foreach (var data in CoinsDetailed)         //Coin Against BTC
                {
                    string  percent_change_1h;
                    decimal Dchange;
                    percent_change_1h = data.percent_change_1h;
                    percent_change_1h = EaseMethods.RemoveExtraText(percent_change_1h);
                    Dchange           = Convert.ToDecimal(percent_change_1h);
                    percent_change_1h = percent_change_1h + "%";
                    if (Dchange > 0)                                                //No Change is seen when BTC is compared against BTC.
                    {
                        if (data.symbol == "BTC")
                        {
                            xBTCv.ForeColor = Color.Black;
                        }
                        else
                        {
                            xBTCv.ForeColor = Color.Green;
                        }
                    }
                    else if (Dchange < 0)
                    {
                        if (data.symbol == "BTC")
                        {
                            xBTCv.ForeColor = Color.Black;
                        }
                        else
                        {
                            xBTCv.ForeColor = Color.Red;
                        }
                    }
                    else if (Dchange == 0)
                    {
                        if (data.symbol == "BTC")
                        {
                            xBTCv.ForeColor = Color.Black;
                        }
                        else
                        {
                            xBTCv.ForeColor = Color.Black;
                        }
                    }
                    string  price_btc;
                    decimal dprice_btc;
                    price_btc  = data.price_btc;
                    price_btc  = EaseMethods.RemoveExtraText(price_btc);
                    dprice_btc = Convert.ToDecimal(price_btc);
                    if (data.symbol == "BTC")
                    {
                        price_btc = String.Format("{0:0.0}", dprice_btc);
                    }
                    else
                    {
                        price_btc = String.Format("{0:0.00000000}", dprice_btc);
                    }
                    price_btc  = price_btc + " BTC";
                    xBTCv.Text = price_btc;
                    break;
                }
                foreach (var data in CoinsDetailed)         //Calculating all things related to percentages for ANY COIN.
                {
                    string  value_changed    = null;
                    string  convertedPercent = null;
                    string  StartingPercent;
                    string  price_usd;
                    decimal Dprice_usd = 0;
                    string  price_aud;
                    decimal Dprice_aud = 0;
                    decimal DChange    = 0;
                    string  price_btc;
                    decimal Dprice_btc = 0;

                    double Dchange = 0;
                    string Data    = null;
                    string StartingPercentP;

                    price_usd = data.price_usd;
                    price_aud = data.price_aud;
                    price_btc = data.price_btc;

                    StartingPercent = data.percent_change_1h;
                    CalculatePercentageValue(value_changed, convertedPercent, StartingPercent, price_usd, Dprice_usd, price_aud, Dprice_aud, price_btc, Dprice_btc, DChange, xUSDc);
                    StartingPercent = data.percent_change_24h;
                    CalculatePercentageValue(value_changed, convertedPercent, StartingPercent, price_usd, Dprice_usd, price_aud, Dprice_aud, price_btc, Dprice_btc, DChange, xUSD24c);
                    StartingPercent = data.percent_change_7d;
                    CalculatePercentageValue(value_changed, convertedPercent, StartingPercent, price_usd, Dprice_usd, price_aud, Dprice_aud, price_btc, Dprice_btc, DChange, xUSD7c);

                    StartingPercentP = data.percent_change_1h;
                    CalculatePercentage(Dchange, Data, StartingPercentP, xUSDp);
                    StartingPercentP = data.percent_change_24h;
                    CalculatePercentage(Dchange, Data, StartingPercentP, xUSD24p);
                    StartingPercentP = data.percent_change_7d;
                    CalculatePercentage(Dchange, Data, StartingPercentP, xUSD7p);
                    break;
                }
            }
        }