2012-06-25 138 views
3

我將如何收到C#股票報價?谷歌財經API是不是非常有幫助從Google財經/雅虎財經獲取行情

+1

dupe http://stackoverflow.com/questions/527703/how-can-i-get-stock-quotes-using-google-finance-api –

+0

也許你需要說明爲什麼Google Finance API不是很好有用嗎? – yamen

回答

0

之一最快的方法是使用Yahoo http請求(一些細節可參見見http://www.gummy-stuff.org/Yahoo-data.htm

然後使用以下代碼來檢索結果編程而不是手動下載或使用電子表格。

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; 
} 

則可以進一步處理返回的字符串,或修改上面的代碼來解析字符串報價的每個分段,成更精細的數據結構。

+0

它不再有效 –