How would I receive a a stock quote onto C#? Google Finance API isn't very helpful
-
1dupe http://stackoverflow.com/questions/527703/how-can-i-get-stock-quotes-using-google-finance-api – Lukasz Madon Jun 25 '12 at 00:10
-
Perhaps you need to say why the Google Finance API isn't very helpful? – yamen Jun 25 '12 at 03:10
3 Answers
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.

- 2,175
- 20
- 23
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.

- 329
- 2
- 3
-
-
Is there a way to get the list of stock names (not their historical data) by index or country? – Elad Benda May 23 '22 at 20:13
I would recommend you to go through Stock quote from Yahoo! in C# article to access stock quote from Yahoo......

- 16,057
- 6
- 39
- 59