我正在尝试计算股票指数日的价值变化 ,如下所述:http: //www.codeproject.com/Articles/37550/Stock-quote-and-chart-from-Yahoo-in-C
在 C# 中如何计算这个?
我正在尝试计算股票指数日的价值变化 ,如下所述:http: //www.codeproject.com/Articles/37550/Stock-quote-and-chart-from-Yahoo-in-C
在 C# 中如何计算这个?
重新设计文章中的 GetQuote 方法...如果您将代码传递给此方法,它将返回 Days Value Change。
public string GetDaysValueChange(string symbol)
{
// Set the return string to null.
string result = null;
try
{
// Use Yahoo finance service to download stock data from Yahoo
// Note that f=w1 tells the service we just want the Days Value Change
string yahooURL = @"http://download.finance.yahoo.com/d/quotes.csv?s=" +
symbol + "&f=w1";
// Initialize a new WebRequest.
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(yahooURL);
// Get the response from the Internet resource.
HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
// Read the body of the response from the server.
StreamReader strm =
new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);
result = strm.ReadLine().Replace("\"", "");
strm.Close();
}
catch
{
// Handle exceptions.
}
// Return the stock quote data in XML format.
return result;
}