获取所有股票符号(指数)股市 - 明智

时间:2013-01-21 12:16:38

标签: api yahoo c#

我对Yahoo Finance 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);
                    }
                }
            }

1 个答案:

答案 0 :(得分:0)

我不知道C#,但是如果你能得到URL后面的结果

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

&amp; 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