コード例 #1
0
        public static async Task <List <StockModel> > GetStockDetails(List <string> symbolStringList)
        {
            var           client     = new HttpClient();
            StringBuilder sb         = new StringBuilder();
            string        baseUri    = @"https://yahoo-finance-low-latency.p.rapidapi.com/v6/finance/quote?symbols=";
            string        symbolsUri = String.Join("%2C", symbolStringList);

            sb.Append(baseUri);
            sb.Append(symbolsUri);

            string uri    = sb.ToString();
            var    apiKey = ConfigurationManager.AppSettings["x-rapidapi-key"];

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(uri),
                Headers    =
                {
                    { "x-rapidapi-key",  apiKey                                     },
                    { "x-rapidapi-host", "yahoo-finance-low-latency.p.rapidapi.com" },
                },
            };

            using (HttpResponseMessage response = client.SendAsync(request).Result)
            {
                QuoteResponse stocks = new QuoteResponse();
                if (response.IsSuccessStatusCode)
                {
                    StockApiResponse result = await response.Content.ReadAsAsync <StockApiResponse>();

                    stocks = result.QuoteResponse;
                }
                else
                {
                    throw new HttpRequestException(response.ReasonPhrase);
                }

                return(stocks.Result.ToList());
            }
        }
コード例 #2
0
        public String GetCurrentStock()
        {
            // Fake response - this would be replaced with a request that is serialized into an object
            StockApiResponse objResponse = new StockApiResponse()
            {
                RequestId = Guid.NewGuid().ToString(),
                TimeStamp = DateTime.Now,

                Stock = new List <StockItem> {
                    new StockItem {
                        Name        = "Product 1",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 2",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 3",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 4",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 5",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 6",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 7",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 8",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 9",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                    new StockItem {
                        Name        = "Product 10",
                        Description = "Placeholder description..",
                        ImageSrc    = "../images/shoe.jpeg",
                        ExternalURL = "https://google.co.uk"
                    },
                }
            };

            // Serialize & return object
            objSeralizer = new JavaScriptSerializer();
            return(objSeralizer.Serialize(objResponse));
        }