Exemplo n.º 1
0
        public void ForexOutput()
        {
            StockMarket stockmarket = new StockMarket("MWSOY45W94DB1V3J");
            string      finalOutputString;

            string [] currencyInput;

            string FromCurrency;
            string ToCurrency;

            currencyInput = currentSelectedCurrencyPair.ToString().Split('2');
            FromCurrency  = currencyInput[0];
            ToCurrency    = currencyInput[1];

            try
            {
                List <FOREX> GetForexInfo = stockmarket.GetForexInfo(FromCurrency, ToCurrency);

                FOREX latestData = GetForexInfo[0];


                string outputString = string.Format("The current open price of {0} is {1:C2}, highest it has been" +
                                                    "is {2:C2}, lower it has been is {3:C2}, close is {4}, FOREX info is pulled at {5}, " +
                                                    "current time is {6:d} at {6:t}", latestData.Pair, latestData.Open, latestData.High, latestData.Low,
                                                    latestData.Close, latestData.Timestamp, DateTime.Now);
                finalOutputString = outputString;

                foreach (FOREX forex in GetForexInfo)
                {
                    string historicalString = String.Format("" +
                                                            "Open: {1:C2} \r\n " +
                                                            "Highest: {2:C2} \r\n " +
                                                            "Lowest: {3:C2} \r\n " +
                                                            "Close: {4} \r\n " +
                                                            "FOREX info is pulled at:  {5}, \r\n  " +
                                                            "Current time: {6:d} at {6:t}", forex.Pair, forex.Open,
                                                            forex.High, forex.Low, forex.Close, forex.Timestamp, DateTime.Now);

                    finalOutputString += "\r\n" + "\r\n" + historicalString;
                }

                resultBox.AppendText(finalOutputString);
                stockPriceBox.Text = latestData.Open.ToString();
            }
            catch (APICallLimitReachedException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception Eex)
            {
                MessageBox.Show(Eex.Message);
            }
        }