Esempio n. 1
0
        /// <summary>
        /// updates the latest stock prices in listview
        /// </summary>
        private async void updateStockPricesInListView()
        {
            mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Aktuellste Wertpapierdaten werden abgefragt...");

            for (int i = 0; i < lvWatchlist.Items.Count; i++)
            {
                StockListitem      slItem        = (StockListitem)lvWatchlist.Items[i].Tag;
                FinanceAPI         rest          = new FinanceAPI(webFinanceStrategy, slItem.symbol);
                Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());
                SingleQuote        stockData     = await taskStockData;
                if (stockData != null)
                {
                    if (webFinanceStrategy == FinanceAPI.FinanceStrategies.Yahoo)
                    {
                        var yahooStock = (YahooSingleQuote)stockData;
                        slItem.BookValue                  = yahooStock.BookValue;
                        slItem.MarketCapitalization       = yahooStock.MarketCapitalization;
                        slItem.FiftydayMovingAverage      = yahooStock.FiftydayMovingAverage;
                        slItem.TwoHundreddayMovingAverage = yahooStock.TwoHundreddayMovingAverage;
                    }

                    slItem.Change            = stockData.Change;
                    slItem.PriceCurrent      = Convert.ToDouble(stockData.CurrentPrice);
                    lvWatchlist.Items[i]     = new ListViewItem(slItem.toStringArray(webFinanceStrategy));
                    lvWatchlist.Items[i].Tag = slItem;
                }
            }

            mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
        }
Esempio n. 2
0
 public void refreshData(SingleQuote stockLatestPrice)
 {
     lblNameInput.Text   = stockLatestPrice.Name;
     lblDateInput.Text   = stockLatestPrice.Date.ToShortDateString();
     lblOpenInput.Text   = stockLatestPrice.Open.ToString();
     lblCloseInput.Text  = stockLatestPrice.CurrentPrice.ToString();
     lblVolumeInput.Text = stockLatestPrice.Volume.ToString();
 }
Esempio n. 3
0
        public void PairWithTest()
        {
            var target     = new SingleQuote();
            var complement = new SingleQuote();

            target.PairWith(complement);
            Assert.Equal(target, complement.PairedWith);
            Assert.Equal(complement.PairedWith, target);
        }
Esempio n. 4
0
 public static string toPriceFormat(this SingleQuote quote, decimal?value)
 {
     if (value != null)
     {
         return(((double)value).ToString("0.00") + " " + quote.Currency.Symbol);
     }
     else
     {
         return("0.00" + quote.Currency.Symbol);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Stores the stock to database if bank has money
        /// </summary>
        private async void saveStockAsync(StockListitem watchlistStock)
        {
            mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Wertpapier wird gekauft...");

            FinanceAPI         rest          = new FinanceAPI(webFinanceStrategy, watchlistStock.symbol);
            Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());

            stockLatestPrice = await taskStockData;

            if (stockLatestPrice != null)
            {
                watchlistStock.PurchaseDate  = DateTime.Now;
                watchlistStock.PricePurchase = stockLatestPrice.CurrentPrice;
                watchlistStock.PriceCurrent  = (double)stockLatestPrice.CurrentPrice;
                if (webFinanceStrategy == FinanceAPI.FinanceStrategies.Yahoo)
                {
                    var yahooStock = stockLatestPrice as YahooSingleQuote;
                    watchlistStock.BookValue                  = yahooStock.BookValue;
                    watchlistStock.MarketCapitalization       = yahooStock.MarketCapitalization;
                    watchlistStock.FiftydayMovingAverage      = yahooStock.FiftydayMovingAverage;
                    watchlistStock.TwoHundreddayMovingAverage = yahooStock.TwoHundreddayMovingAverage;
                }
                decimal totalSum = Convert.ToDecimal(watchlistStock.PriceCurrent * watchlistStock.Quantity);
                var     bank     = bankModel.getBank();

                if (totalSum <= bank.AccountBalance)
                {
                    Task <int> insertTask = Task.Run(() => depotModel.insertStockToDepot(watchlistStock));
                    int        id         = await insertTask;
                    if (id > 0)
                    {
                        depotModel.saveTransaction(TransactionItem.TransactionTypeEnum.Purchase, watchlistStock);
                        watchlistStock.StocksMapID = id;

                        // Add to listview
                        var lvItem = new ListViewItem(watchlistStock.toStringArray());
                        lvItem.Tag = watchlistStock;
                        lvDepot.Items.Add(lvItem);

                        // Draw Chart
                        selectedStock = watchlistStock;
                        loadChartDataAsync(selectedStock);
                    }
                }
                else
                {
                    MessageBox.Show("Nicht genügend Geld auf der Bank");
                }
            }
            mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
        }
Esempio n. 6
0
        /// <summary>
        /// Prepares data for stock chart and detail view
        /// </summary>
        private async void loadChartDataAsync(StockListitem selectedItem = null)
        {
            if (selectedItem != null)
            {
                mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Wertpapierdaten für " + selectedItem.name + " werden abgefragt...");

                FinanceAPI rest = new FinanceAPI(webFinanceStrategy, selectedItem.symbol);

                drawChart(selectedItem);
                Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());
                stockLatestPrice = await taskStockData;
                fillRightSidebarWithData();

                mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Asynchronous method to load the depot value
        /// </summary>
        private async void btnUpdateDepot_Click(object sender, EventArgs e)
        {
            mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Börsendaten werden abgerufen...");

            var     depot        = depotModel.getUserDepot();
            var     stocks       = depotModel.getStocks();
            decimal?depotBalance = 0;

            foreach (var item in stocks)
            {
                FinanceAPI         rest          = new FinanceAPI(webFinanceStrategy, item.symbol);
                Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());
                SingleQuote        stockData     = await taskStockData;

                if (stockData != null)
                {
                    if (stockData.Currency.ShortCode == defaultCurrency)
                    {
                        depotBalance += (stockData.CurrentPrice * item.Quantity);
                    }
                    else
                    {
                        string currencyPair = "" + stockData.Currency.ShortCode + defaultCurrency;
                        if (!currencyRates.ContainsKey(currencyPair))
                        {
                            Task <CurrencyRate> taskCurrencyData = Task.Run(() => new FinanceAPI(webFinanceStrategy, currencyPair).getCurrencyRate());
                            CurrencyRate        currencyRate     = await taskCurrencyData;
                            if (currencyRate != null)
                            {
                                depotBalance += stockData.CurrentPrice * item.Quantity * Convert.ToDecimal(currencyRate.Rate);
                                currencyRates.Add(currencyPair, currencyRate.Rate);
                            }
                        }
                        else
                        {
                            depotBalance += stockData.CurrentPrice * item.Quantity * Convert.ToDecimal(currencyRates[currencyPair]);
                        }
                    }
                }
            }

            lblDepotBalance.Text = ((double)depotBalance).ToString("0.00");

            mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
        }
Esempio n. 8
0
        /// <summary>
        /// prepares data for stock chart and detail view
        /// </summary>
        private async void loadChartDataAsync(StockListitem selectedItem)
        {
            if (selectedItem != null)
            {
                mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Chart wird gezeichnet...");

                FinanceAPI rest = new FinanceAPI(webFinanceStrategy, selectedItem.symbol);

                drawChart(selectedItem);

                Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());
                stockLatestPrice = await taskStockData;

                if (stockLatestPrice != null)
                {
                    fillRightSidebarWithData();
                    additionalStockData(selectedItem);
                    mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Inserts the stock to the watchlist
        /// </summary>
        private async void insertStockAsync(StockListitem watchlistStock)
        {
            mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Aktie wird gespeichert...");

            FinanceAPI         rest          = new FinanceAPI(webFinanceStrategy, watchlistStock.symbol);
            Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());

            stockLatestPrice = await taskStockData;

            if (stockLatestPrice != null)
            {
                watchlistStock.Change        = stockLatestPrice.Change;
                watchlistStock.PurchaseDate  = DateTime.Now;
                watchlistStock.PricePurchase = stockLatestPrice.CurrentPrice;
                watchlistStock.PriceCurrent  = Convert.ToDouble(stockLatestPrice.CurrentPrice);
                watchlistStock.StocksMapID   = model.insertStockToWatchlist(watchlistStock);

                if (webFinanceStrategy == FinanceAPI.FinanceStrategies.Yahoo)
                {
                    var yahooStock = stockLatestPrice as YahooSingleQuote;
                    watchlistStock.BookValue                  = yahooStock.BookValue;
                    watchlistStock.MarketCapitalization       = yahooStock.MarketCapitalization;
                    watchlistStock.FiftydayMovingAverage      = yahooStock.FiftydayMovingAverage;
                    watchlistStock.TwoHundreddayMovingAverage = yahooStock.TwoHundreddayMovingAverage;
                }
                selectedStock = watchlistStock;
                loadChartDataAsync(watchlistStock);

                // Add to listview
                var lvItem = new ListViewItem(watchlistStock.toStringArray());
                lvItem.Tag = watchlistStock;
                lvWatchlist.Items.Add(lvItem);
            }
            else
            {
                MessageBox.Show("Es konnten keine Preisinformationen für das Wertpapier gefunden werden.");
            }

            mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
        }
Esempio n. 10
0
 /// <summary>
 /// When user selects a stock, another dialog occurs where he can see his proposal
 /// </summary>
 private async void makeBuyProposition()
 {
     if (selectedStock != null)
     {
         FinanceAPI         rest          = new FinanceAPI(webFinanceStrategy, selectedStock.symbol);
         Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());
         stockLatestPrice = await taskStockData;
         if (stockLatestPrice != null && stockLatestPrice.CurrentPrice > 0)
         {
             toggleToolbar(false);
             selectedStock.PriceCurrent = Convert.ToDouble(stockLatestPrice.CurrentPrice);
             lblBuyName.Text            = selectedStock.name;
             lblBuyPrice.Text           = selectedStock.toPriceFormat(selectedStock.PriceCurrent);
             var total = (selectedStock.PriceCurrent * Convert.ToDouble(nupStockQuantity.Value));
             lblBuyTotal.Text = selectedStock.toPriceFormat(total);
         }
         else
         {
             MessageBox.Show("Es konnten keine Preisinformationen für das Wertpapier gefunden werden.");
         }
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Creates a single quote from a string downloaded from Google Finance
        /// </summary>
        public SingleQuote createSingleQuoteFromString(string csvString)
        {
            SingleQuote quote = null;

            if (csvString != null)
            {
                string[] elements = csvString.Split(',');
                if (!String.IsNullOrEmpty(elements[0]))
                {
                    quote = new GoogleSingleQuote()
                    {
                        Date   = Convert.ToDateTime(elements[0]),
                        Open   = Convert.ToDecimal(elements[1], CultureInfo.InvariantCulture),
                        High   = Convert.ToDecimal(elements[2], CultureInfo.InvariantCulture),
                        Low    = Convert.ToDecimal(elements[3], CultureInfo.InvariantCulture),
                        Close  = Convert.ToDecimal(elements[4], CultureInfo.InvariantCulture),
                        Volume = getVolume(elements[5])
                    };
                    quote.Change = (double)quote.CurrentPrice - (double)quote.Open;
                }
            }
            return(quote);
        }
Esempio n. 12
0
        public void SingleQuoteConstructorTest()
        {
            var target = new SingleQuote();

            Check.That(target).HasFieldsWithSameValues(new { Text = "'", LiteralCharacter = '\'' });
        }
 public void SingleQuoteExceptionTest( )
 {
     char result = SingleQuote.Parse("\"");
 }
        public void SingleQuoteTest( )
        {
            char result = SingleQuote.Parse("'");

            Assert.AreEqual('\'', result);
        }
Esempio n. 15
0
        /// <summary>
        /// updates the latest stock prices in listview
        /// </summary>
        private async void updateStockPricesInListViewAsync()
        {
            mainForm.notifyUser(FrmMain.NotifyType.PrepareMessage, "Wertpapierdaten werden aktualisiert...");
            double depotCurrent = 0.00;
            double depotStart   = 0.00;

            for (int i = 0; i < lvDepot.Items.Count && lvDepot.Items.Count > 0; i++)
            {
                StockListitem      slItem        = (StockListitem)lvDepot.Items[i].Tag;
                FinanceAPI         rest          = new FinanceAPI(webFinanceStrategy, slItem.symbol);
                Task <SingleQuote> taskStockData = Task.Run(() => rest.getLatestQuote());
                SingleQuote        stockData     = await taskStockData;
                if (stockData != null && null != lvDepot.Items[i])
                {
                    if (webFinanceStrategy == FinanceAPI.FinanceStrategies.Yahoo)
                    {
                        var yahooStock = (YahooSingleQuote)stockData;
                        slItem.BookValue                  = yahooStock.BookValue;
                        slItem.MarketCapitalization       = yahooStock.MarketCapitalization;
                        slItem.FiftydayMovingAverage      = yahooStock.FiftydayMovingAverage;
                        slItem.TwoHundreddayMovingAverage = yahooStock.TwoHundreddayMovingAverage;
                    }

                    slItem.Change       = stockData.Change;
                    slItem.PriceCurrent = Convert.ToDouble(stockData.CurrentPrice);

                    lvDepot.Items[i]     = new ListViewItem(slItem.toStringArray(webFinanceStrategy));
                    lvDepot.Items[i].Tag = slItem;
                    if (slItem.Currency.ShortCode == defaultCurrency)
                    {
                        depotCurrent += (double)slItem.PriceCurrent * (double)slItem.Quantity;
                        depotStart   += (double)slItem.PricePurchase * (double)slItem.Quantity;
                    }
                    else
                    {
                        string currencyPair = "" + slItem.Currency.ShortCode + defaultCurrency;
                        if (!currencyRates.ContainsKey(currencyPair))
                        {
                            Task <CurrencyRate> taskCurrencyData = Task.Run(() => new FinanceAPI(webFinanceStrategy, currencyPair).getCurrencyRate());
                            CurrencyRate        currencyRate     = await taskCurrencyData;
                            if (currencyRate != null)
                            {
                                depotCurrent += (double)slItem.PriceCurrent * (double)slItem.Quantity * currencyRate.Rate;
                                depotStart   += (double)slItem.PricePurchase * (double)slItem.Quantity * currencyRate.Rate;
                                currencyRates.Add(currencyPair, currencyRate.Rate);
                            }
                        }
                        else
                        {
                            depotCurrent += (double)slItem.PriceCurrent * (double)slItem.Quantity * currencyRates[currencyPair];
                            depotStart   += (double)slItem.PricePurchase * (double)slItem.Quantity * currencyRates[currencyPair];
                        }
                    }
                }
            }

            lblDepotCurrent.Text = depotCurrent.ToString("0.00");
            lblDepotStart.Text   = depotStart.ToString("0.00");
            calculateDepotChanges();
            mainForm.notifyUser(FrmMain.NotifyType.StatusMessage);
        }
Esempio n. 16
0
 public static string toPriceFormat(this SingleQuote quote, double value)
 {
     return(value.ToString("0.00") + " " + quote.Currency.Symbol);
 }