Ejemplo n.º 1
0
        public static HodlStatus GetCurrent(List <Transaction> transactions, FiatConvert convert = null, string fiatPref = null)
        {
            HodlStatus status = new HodlStatus();

            if (fiatPref == null)
            {
                fiatPref = AppUtils.FiatPref;
            }

            foreach (var tr in transactions)
            {
                double thisFiat = AppUtils.ConvertFiat(tr.FiatCurrency, fiatPref, tr.FiatValue, convert);

                if (tr.AcquireCrypto)
                {
                    status.TotalCryptos[tr.CryptoCurrency] += tr.CryptoAmount;

                    // take from floating cash if possible
                    if (status.FloatingFiat > 0)
                    {
                        double newFloating = status.FloatingFiat;
                        if (newFloating >= thisFiat)
                        {
                            newFloating -= thisFiat;
                            thisFiat     = 0;
                        }
                        else
                        {
                            thisFiat -= newFloating;
                        }
                        status.FloatingFiat = newFloating;
                    }

                    status.TotalFiatInvestment += thisFiat;
                }
                else
                {
                    status.TotalCryptos[tr.CryptoCurrency] -= tr.CryptoAmount;
                    status.FloatingFiat += thisFiat;
                }
            }

            foreach (string crypto in AppUtils.CryptoCurrencies)
            {
                status.CryptoFiatVal += AppUtils.GetFiatValOfCrypto(
                    fiatPref,
                    crypto,
                    status.TotalCryptos[crypto],
                    convert);
            }

            return(status);
        }
Ejemplo n.º 2
0
        private void UpdateLabels()
        {
            if (transactions == null)
            {
                return;
            }

            HodlStatus status = HodlStatus.GetCurrent(transactions);

            portfolioGrid.Children.Clear();
            portfolioGrid.ColumnDefinitions.Clear();

            for (int i = 0; i < AppUtils.CryptoCurrencies.Length; i++)
            {
                string key = AppUtils.CryptoCurrencies[i];
                portfolioGrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                portfolioGrid.Children.Add(new Label
                {
                    HorizontalTextAlignment = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    FontSize = 12,
                    Text     = string.Format(
                        "{0:0.000000} {1}",
                        status.TotalCryptos[key],
                        key)
                }, i, 0);
                portfolioGrid.Children.Add(
                    new Label
                {
                    HorizontalTextAlignment = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    FontSize = 12,
                    Text     = AppUtils.GetMoneyString(AppUtils.GetFiatValOfCrypto(
                                                           AppUtils.FiatPref,
                                                           key,
                                                           status.TotalCryptos[key]),
                                                       AppUtils.FiatPref)
                }, i, 1);
                portfolioGrid.Children.Add(
                    new Label
                {
                    HorizontalTextAlignment = TextAlignment.Center,
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    FontSize = 11,
                    Text     = "at " + AppUtils.GetMoneyString(
                        AppUtils.ConvertFiat(
                            "USD",
                            AppUtils.FiatPref,
                            AppUtils.FiatConvert.UsdToCrypto[key]),
                        AppUtils.FiatPref)
                }, i, 2);
            }

            cashValueLabel.Text = "Cashed out: " + AppUtils.GetMoneyString(status.FloatingFiat, AppUtils.FiatPref);
            userValueLabel.Text = AppUtils.GetMoneyString(status.CryptoFiatVal, AppUtils.FiatPref);

            string profLoss  = (status.Profit >= 0) ? "Profit" : "Loss";
            string plusMinus = (status.Profit >= 0) ? "+" : "-";

            profitLabel.TextColor = (status.Profit >= 0) ? Color.ForestGreen : Color.IndianRed;
            profitLabel.Text      = string.Format("{0}: {1} ({2}{3:0.0}%)",
                                                  profLoss,
                                                  AppUtils.GetMoneyString(Math.Abs(status.Profit), AppUtils.FiatPref),
                                                  plusMinus,
                                                  Math.Abs(status.PercentChange));

            // Update the user's widgets if they have any
            DependencyService.Get <IWidgetManager>().UpdateWidget(status.CryptoFiatVal, status.Profit, AppUtils.FiatPref);
        }