コード例 #1
0
        async void Click_For_Get(object sender, EventArgs e)
        {
            string U_Input;

            U_Input = Enter_Stock.Text;
            string              API_End  = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY" + "&symbol=" + U_Input + "&apikey=" + API_Key;
            Uri                 StockAPI = new Uri(API_End);
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(StockAPI);

            string Read_Json = await response.Content.ReadAsStringAsync();

            var Stock_Info = StockData.FromJson(Read_Json);

            Console.WriteLine(Read_Json);
            if (Read_Json != StockAppVars.Error)
            {
                StockAppVars.ListOfStocks = Stock_Info.TimeSeriesDaily.Values.ToList();
                StockAppVars.ListofDates  = Stock_Info.TimeSeriesDaily.Keys.ToList();
                List <DayData> DaysList = new List <DayData>();
                for (int i = 0; i < StockAppVars.ListOfStocks.Count; i++)
                {
                    //Single_Day.date = StockAppVars.ListofDates[i];
                    Single_Day.date  = StockAppVars.ListofDates[i].ToString();
                    temp             = Single_Day.date.Substring(4, 4).Trim('-');
                    Single_Day.date  = ThisIsTheMonth[Convert.ToInt32(temp)] + " " + Single_Day.date.Substring(8, 2) + ", " + Single_Day.date.Substring(0, 4);
                    Single_Day.high  = double.Parse(StockAppVars.ListOfStocks[i].The_High);
                    Single_Day.low   = double.Parse(StockAppVars.ListOfStocks[i].The_Low);
                    Single_Day.close = double.Parse(StockAppVars.ListOfStocks[i].The_Close);
                    DaysList.Add(Single_Day);
                    Single_Day = new DayData();
                }
                historyListView.ItemsSource = DaysList;
                Populate();
                StockAppVars.R_Call = true;
            }
            else
            {
                DisplayAlert("Something went wrong", "Provided stock symbol not valid", "OK");
            }
        }
コード例 #2
0
        async void HandleGetStock(object sender, EventArgs e)
        {
            //USER INPUT
            string UserInput;

            UserInput = GetStock.Text; //User input that is used to retrieve the desired company ancronym

            //adding the user input to the api endpoint, and converting it to a URI variable
            string StockApiEndpoint = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY" + "&symbol=" + UserInput + "&apikey=" + key;
            Uri    StockApiUri      = new Uri(StockApiEndpoint);

            //A class instance that is used to send HTTP requests and receive HTTP responses
            HttpClient client = new HttpClient();

            //gets data from api
            HttpResponseMessage response = await client.GetAsync(StockApiUri);

            //string
            string jsonContent = await response.Content.ReadAsStringAsync();

            //parse into an object according to data model
            var stockData = StockData.FromJson(jsonContent);

            //if an error wasn't returned
            if (jsonContent != GlobalVariables.ErrorString)
            {
                //convert dictionary to list
                GlobalVariables.StockList = stockData.TimeSeriesDaily.Values.ToList();
                GlobalVariables.DatesList = stockData.TimeSeriesDaily.Keys.ToList();

                List <DayData> DayList = new List <DayData>();

                for (int i = 0; i < 30; i++)
                {
                    //data model equal to api equivalent.
                    //reminder parsing means to take one form of data and converting it to another
                    //data model defines how information is stoed and retrieced to support solution.
                    dailydata.date  = GlobalVariables.DatesList[i];
                    dailydata.high  = double.Parse(GlobalVariables.StockList[i].The2High);
                    dailydata.low   = double.Parse(GlobalVariables.StockList[i].The3Low);
                    dailydata.close = double.Parse(GlobalVariables.StockList[i].The4Close);

                    //add dailydata to list
                    DayList.Add(dailydata);
                    dailydata = new DayData();
                }

                historyListView.ItemsSource = DayList;

                //populate rest of the fields ins the page
                populatePage();
                GlobalVariables.retreived = true;
                entries.Clear();
                ChartView.Chart = new LineChart {
                    Entries = entries, BackgroundColor = SKColors.Transparent
                };

                FillChart();
                ChartView.Chart = new LineChart {
                    Entries = entries, BackgroundColor = SKColors.Transparent,
                };
            }
            else
            {
                await DisplayAlert("ERROR", "Invalid Stock Symbol", "OK");
            }
        }
コード例 #3
0
        async void GetStockButton_Clicked(object sender, EventArgs e)
        {
            //Getting company's acronym entered by the user in order to be added to the api endpoint
            string userInput;

            userInput = stockEntry.Text;

            //Adding the user input to the base api endpoint and converting into an "Uri" variable.
            string stockApiEndpoint = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY" + "&symbol=" + userInput + "&apikey=" + API_Key;
            Uri    stockApiUri      = new Uri(stockApiEndpoint);

            //creating a HTTP client variable
            HttpClient client = new HttpClient();

            //Response holder
            HttpResponseMessage response = await client.GetAsync(stockApiUri);

            //response stream into a string (we wait for the whole reponse to be received)
            string jsonContent = await response.Content.ReadAsStringAsync();

            //Parse into an object accroding to our data model (StockData)
            var stockData = StockData.FromJson(jsonContent);

            //Console.WriteLine(jsonContent);

            if (jsonContent != GlobalVariables.errorString)
            {
                //Convert the dictionary into a list
                GlobalVariables.stockList = stockData.TimeSeriesDaily.Values.ToList();
                GlobalVariables.datesList = stockData.TimeSeriesDaily.Keys.ToList();

                List <DayData> DaysList = new List <DayData>();

                for (int i = 0; i < GlobalVariables.stockList.Count; i++)
                {
                    //Console.WriteLine("test1");
                    //Console.WriteLine(datesList[i]);
                    //Console.WriteLine(stockList[i].The2High);
                    //Console.WriteLine(stockList[i].The3Low);

                    aDay.date  = GlobalVariables.datesList[i];
                    aDay.high  = double.Parse(GlobalVariables.stockList[i].The2High);
                    aDay.low   = double.Parse(GlobalVariables.stockList[i].The3Low);
                    aDay.close = double.Parse(GlobalVariables.stockList[i].The4Close);

                    //Console.WriteLine("test2");

                    DaysList.Add(aDay);
                    //DaysList

                    //Console.WriteLine("test3");

                    //Console.WriteLine("test4");
                    //Console.WriteLine(DaysList[i].date);
                    //Console.WriteLine(DaysList[i].high);
                    //Console.WriteLine(DaysList[i].low);

                    //Console.WriteLine("test5");

                    aDay = new DayData();

                    //Console.WriteLine("test6");
                }

                //Setting the list as the source of the ListView
                historyListView.ItemsSource = DaysList;

                //populating the rest of the fields in the page
                populatePage();
                GlobalVariables.retreived = true;
            }
            else
            {
                DisplayAlert("ERROR", "Invalid Stock Symbol", "OK");
            }
        }