C# 从谷歌财经/雅虎财经获取报价

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11182161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 16:54:20  来源:igfitidea点击:

Get Quotes from Google Finance / Yahoo Finance

c#finance

提问by user1243565

How would I receive a a stock quote onto C#? Google Finance API isn't very helpful

我如何在 C# 上接收股票报价?Google Finance API 不是很有帮助

回答by Akash KC

I would recommend you to go through Stock quote from Yahoo! in C#article to access stock quote from Yahoo......

我建议您查看雅虎的股票报价!在 C#文章中访问来自雅虎的股票报价......

回答by Blueberry

Have you looked at this? Very useful examples.

你看过这个吗?非常有用的例子。

http://www.jarloo.com/real-time-google-stock-api/

http://www.jarloo.com/real-time-google-stock-api/

回答by kusnaditjung tjung

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)

最快的方法之一是使用 yahoo http 请求(一些详细信息可以在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.

然后你可以进一步处理返回的字符串,或者修改上面的代码以将引号的每个段的字符串解析为更详细的数据结构。

回答by Programming with Mark

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.

Google 财经 API 替代方案。AlphaVantage是 Google 财务 API 的一个免费、出色的替代品。您可以注册一个免费的 API 密钥以开始检索实时和历史股票市场报价。

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).

如何使用 C# 检索 AlphaVantage 股票市场数据?下面是一些示例代码,用于在 C# 中检索每月股票市场价格。您将需要安装ServiceStack.Text- 一个免费的、开源的、高性能的 .NET 文本实用程序来运行以下 (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.

您可以在此处在 gistlyn 中运行上面的示例代码。我已经写了一个完整的文章“AlphaVantage和C#”在这里