Ejemplo n.º 1
0
        private async void WalletForm_Load(object sender, EventArgs e)
        {
            foreach (User u in bazadanych.Users.Where(x => x.username == UsernameText))
            {
                currentBalance    = u.balance;
                labelBalance.Text = currentBalance.ToString("N");
                foreach (Payment p in bazadanych.Payments.Where(x => x.id_user == u.id_user))
                {
                    foreach (Price pr in bazadanych.Prices.Where(x => x.Id == p.id_price))
                    {
                        foreach (Currency c in bazadanych.Currencies.Where(x => x.Id == pr.Id_Currency))
                        {
                            if (!IdListOfCurrencies.ContainsKey(c.Id))
                            {
                                IdListOfCurrencies.Add(c.Id, c.Name);
                            }
                        }
                    }
                }
                list = new List <string[]>();
                string[] row = null;
                foreach (var el in IdListOfCurrencies.Distinct())
                {
                    foreach (Currency o in bazadanych.Currencies.Where(x => x.Id == el.Key))
                    {
                        string      priceAPI  = "https://min-api.cryptocompare.com/data/price?fsym=" + o.Name + "&tsyms=USD";
                        WebRequest  request3  = WebRequest.Create(priceAPI);
                        WebResponse response3 = await request3.GetResponseAsync();

                        string answer = string.Empty;
                        using (Stream s = response3.GetResponseStream())
                        {
                            using (StreamReader reader = new StreamReader(s))
                            {
                                answer = await reader.ReadToEndAsync();
                            }
                        }
                        Coins.Price price = JsonConvert.DeserializeObject <Coins.Price>(answer);
                        currentPrice = price.USD;
                    }
                    amountOfCurrency(el.Key);
                    row = new string[]
                    {
                        el.Value,
                        CurrencyAmount.ToString(),
                        (CurrencyAmount * currentPrice).ToString("N")
                    };
                    list.Add(row);
                }
                RefreshList(list);
            }
        }
Ejemplo n.º 2
0
        public async void UpdateDashboard()
        {
            foreach (Currency o in bazadanych.Currencies.Where(x => x.Name == textBoxListOfCurrencies.Text))
            {
                string Url     = "https://www.cryptocompare.com" + o.ImageUrl;
                var    request = WebRequest.Create(Url);
                using (var response = request.GetResponse())
                    using (var stream = response.GetResponseStream())
                    {
                        DashboardCurrencyIcon.Image = Bitmap.FromStream(stream);
                    }

                textBoxPriceInUSD.Text = o.Name + "/USD";

                string     priceAPI = "https://min-api.cryptocompare.com/data/price?fsym=" + CurrentCurrency + "&tsyms=USD";
                WebRequest request3 = WebRequest.Create(priceAPI);

                WebResponse response3 = await request3.GetResponseAsync();

                string answer = string.Empty;

                using (Stream s = response3.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(s))
                    {
                        answer = await reader.ReadToEndAsync();
                    }
                }


                Coins.Price price = JsonConvert.DeserializeObject <Coins.Price>(answer);
                CurrentPrice         = price.USD;
                labelPriceInUSD.Text = CurrentPrice.ToString("N") + "$";
                response3.Close();

                foreach (Currency c in bazadanych.Currencies.Where(x => x.Name == CurrentCurrency))
                {
                    id_currency = c.Id;
                }
                foreach (User u in bazadanych.Users.Where(x => x.username == UsernameText))
                {
                    CurrentBalance  = Math.Round(u.balance, 2);
                    usdBalance.Text = "USD balance: " + Math.Round(CurrentBalance, 2).ToString("N") + "$";
                }
                amountOfCurrency();
                CurrentAmount     = amount;
                tokenBalance.Text = "Token balance: " + amount.ToString();
            }
        }
Ejemplo n.º 3
0
        private async void TradingForm_Load(object sender, EventArgs e)
        {
            list = new List <string[]>();
            string[] row = null;
            foreach (User u in bazadanych.Users.Where(x => x.username == UsernameText))
            {
                foreach (Payment p in bazadanych.Payments.Where(x => x.id_user == u.id_user))
                {
                    foreach (Price pr in bazadanych.Prices.Where(x => x.Id == p.id_price))
                    {
                        foreach (Currency c in bazadanych.Currencies.Where(x => x.Id == pr.Id_Currency))
                        {
                            row = new string[]
                            {
                                pr.DataTime.ToString(),
                          c.Name,
                          p.amount.ToString(),
                          pr.Price1.ToString("N")
                            };
                            list.Add(row);

                            USDspent += p.amount * pr.Price1;
                        }
                    }
                }
            }
            RefreshList(list);
            List <string> distinct             = (List <string>)list.Select(x => x[1]).Distinct().ToList();
            Dictionary <string, double> prices = new Dictionary <string, double>();

            foreach (var el in distinct)
            {
                string     priceAPI = "https://min-api.cryptocompare.com/data/price?fsym=" + el + "&tsyms=USD";
                WebRequest request  = WebRequest.Create(priceAPI);

                WebResponse response = await request.GetResponseAsync();

                string answer = string.Empty;

                using (Stream s = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(s))
                    {
                        answer = await reader.ReadToEndAsync();
                    }
                }
                Coins.Price price = JsonConvert.DeserializeObject <Coins.Price>(answer);
                prices.Add(el, price.USD);
                response.Close();
            }

            foreach (var el in prices)
            {
                foreach (Currency c in bazadanych.Currencies.Where(x => x.Name == el.Key))
                {
                    amountOfCurrency(c.Id);
                    CurrentPrice += CurrencyAmount * el.Value;
                }
            }
            Revenue = CurrentPrice - USDspent;
            double cena    = Math.Round(Revenue, 2);
            double procent = Math.Round(((Revenue * 100) / USDspent), 2);

            if (cena > 0)
            {
                pictureBoxRevenue.Image         = Properties.Resources.increase;
                labelRevenueInDollars.Text      = "+" + cena.ToString("N") + "$";
                labelRevenueInProcent.Text      = "+" + procent.ToString() + "%";
                labelRevenueInDollars.ForeColor = Color.Green;
                labelRevenueInProcent.ForeColor = Color.Green;
            }
            else
            {
                pictureBoxRevenue.Image         = Properties.Resources.decrease;
                labelRevenueInDollars.Text      = cena.ToString("N") + "$";
                labelRevenueInProcent.Text      = procent.ToString() + "%";
                labelRevenueInDollars.ForeColor = Color.Red;
                labelRevenueInProcent.ForeColor = Color.Red;
            }
        }