1

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

1 回答 1

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

&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

于 2013-03-01T15:48:18.137 回答