How would I receive a a stock quote onto C#? Google Finance API isn't very helpful
To obtain a real-time quote on Yahoo! Finance, users simply need to select the "Real-time ECN" option from the quotes drop-down menu on the Yahoo! Finance main page. An alternate way to display real-time quotes is to obtain a basic quote, or view a portfolio, and then click the "Real-time ECN" View link.
Yahoo Finance provides real-time streaming quotes for many exchanges. Real-time data is available during an exchange's market hours, and in some cases during pre-market and post-market hours.
The YAHOOFINANCE formula extends the functionality of GOOGLEFINANCE as it offers a much more comprehensive data set for stock tickers. You can easily pull Yahoo Finance data into your Google Sheets automatically using the Google Apps Script.
Google Finance API Alternative. A free, excellent alternative to Google's Finance API is AlphaVantage. You can sign up for a free API key to start retrieving live & historical stock market quotes.
How to retrieve AlphaVantage Stock Market Data using C#? Here is some sample code to retrieve monthly stock market prices in C#. You will need to install ServiceStack.Text - a free, open-source, high performance .NET text utility to run the below (Install-Package ServiceStack.Text).
public class AlphaVantageData
{
public DateTime Timestamp { get; set; }
public decimal Open { get; set; }
public decimal High { get; set; }
public decimal Low { get; set; }
public decimal Close { get; set; }
public decimal Volume { get; set; }
}
// retrieve monthly prices for Microsoft
var symbol = "MSFT";
var apiKey = "demo"; // retrieve your api key from https://www.alphavantage.co/support/#api-key
var monthlyPrices = $"https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol={symbol}&apikey={apiKey}&datatype=csv"
.GetStringFromUrl().FromCsv<List<AlphaVantageData>>();
monthlyPrices.PrintDump();
You can run above sample code in gistlyn here. I have written a full article "AlphaVantage and C#" here.
One of the quickest way is to using yahoo http request (some details can be found in see http://www.gummy-stuff.org/Yahoo-data.htm )
Then using the following code to retrieve the result programmatically instead of manual download or using spreadsheet.
public static string Extract(string yahooHttpRequestString)
{
//if need to pass proxy using local configuration
System.Net.WebClient webClient = new WebClient();
webClient.Proxy = HttpWebRequest.GetSystemWebProxy();
webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
Stream strm = webClient.OpenRead(yahooHttpRequestString);
StreamReader sr = new StreamReader(strm);
string result = sr.ReadToEnd();
strm.Close();
return result;
}
then you can process the returned string further, or modify the above code to parse the string for each segment of the quote, into a more elaborated data structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With