2013-01-21 134 views
1

我沒有太多的雅虎財經API經驗。我需要從雅虎使用此API獲取股票市場上的所有股票代碼。有人可以幫助我達到這個目的嗎?獲取所有股票符號(指數)股票市場明智

我認爲這可以通過從雅虎下載股票數據來實現。

我試着進入http://code.google.com/p/yahoo-finance-managed/[^]的示例代碼,但沒有運氣。

我很感激任何幫助。

到目前爲止,我已經試過這樣:

TextWriter tw = File.CreateText("StockData.csv"); 
      AlphabeticIDIndexDownload dl1 = new AlphabeticIDIndexDownload(); 
      dl1.Settings.TopIndex = null;      
      Response<AlphabeticIDIndexResult> resp1 = dl1.Download(); 

      tw.WriteLine("Id|Isin|Name|Exchange|Type|Industry"); 
      Console.WriteLine("Id|Isin|Name|Exchange|Type|Industry"); 
      foreach (var alphabeticalIndex in resp1.Result.Items) 
      { 
       AlphabeticalTopIndex topIndex = (AlphabeticalTopIndex)alphabeticalIndex; 
       dl1.Settings.TopIndex = topIndex; 
       Response<AlphabeticIDIndexResult> resp2 = dl1.Download(); 
       foreach (var index in resp2.Result.Items) 
       { 
        IDSearchDownload dl2 = new IDSearchDownload(); 
        Response<IDSearchResult> resp3 = dl2.Download(index);     
        foreach (var item in resp3.Result.Items) 
        { 
         tw.WriteLine(item.ID + "|" + item.ISIN + "|" + item.Name + "|" + item.Exchange + "|" + item.Type + "|" + item.Industry); 
         Console.WriteLine(item.ID + "|" + item.ISIN + "|" + item.Name + "|" + item.Exchange + "|" + item.Type + "|" + item.Industry + "Exchange: " + item.Exchange); 
        } 
       } 
      } 

回答

0

我不知道C#,但如果你能得到以下網址的結果

http://download.finance.yahoo.com/d/quotes.csv?s=AAPL+MSFT&f=nxl1c1p2poabt8mwva2j1re7yhgs 

using System.Net; 
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 
    HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
    Stream resStream = response.GetResponseStream(); 

你將得到結果CSV,每個請求符號將包含兩行 - MSFT和AAPL:

Apple Inc.,NasdaqNM,432.8399,-8.5601,-1.94%,441.4,438,432.84,432.75,630.24,432.45 - 438.1799,435.00 - 705.07,6073652,20595200,406.5B,10.01,44.7,1.8,438.1799,432.45,AAPL 
Microsoft Corpora,NasdaqNM,27.59,-0.21,-0.76%,27.8,27.69,27.6,27.59,33.11,27.52 - 27.76,26.26 - 32.95,7088381,47882500,231.1B,15.27,2.85,3.09,27.76,27.52,MSFT 

的& F = ...是你想要的響應的格式,包括在這個例子中,以下幾點:

company: 'n', 
    exchange: 'x', 
    last: 'l1', 
    change: 'c1', 
    percent_change: 'p2', 
    prev_close: 'p', 
    open: 'o', 
    bid: 'a', 
    ask: 'b', 
    one_year_target: 't8', 
    day_range: 'm', 
    fifty_two_week_range: 'w', 
    volume: 'v', 
    average_daily_volume: 'a2', 
    market_cap: 'j1', 
    p_e_ratio: 'r', 
    eps: 'e7', 
    div_yield: 'y', 
    day_high: 'h', 
    day_low: 'g', 
    symbol: 's' 

查看完整列表在這裏http://www.gummy-stuff.org/Yahoo-data.htm

現在只是解析CSV例如https://stackoverflow.com/a/2081430/514463

+0

這並不提供所有符號的完整列表,只是您在請求中指定的符號的詳細信息。 – Martin

+0

是否要API調用返回所有符號或所有可用符號的所有股票報價?對於前者,我認爲至少有一個免費的API是不可能的,對於後者,你可以下載一個符號列表,例如http://www.nasdaq.com/screening/company-list.aspx – DavidC

+0

是的,在特定交易所交易的股票的完整列表。我還沒有看到任何免費提供這項服務的服務。對納斯達克來說都是好事,但我也會喜歡其他一些交易所。 – Martin