推荐一个实时的汇率api?

可靠性,实时性都比较好的

阅读 33.7k
6 个回答

汇率

  1. http://stackoverflow.com/questions/10040954/alternative-to-google-finance-api
  2. http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote
  3. http://blog.programmableweb.com/2008/04/24/25-finance-apis/

上证,深证等

  1. http://www.cnblogs.com/kingwolfofsky/archive/2011/08/14/2138081.html

代码共享(ruby)

# coding: utf-8                                                                 
require 'nokogiri'
require 'csv'
require 'net/http'

FXs = [ 
       'JPY',
       'AUD',
       'XAU',
       'EUR',
       'GBP'
      ]   
GUs = [ 
       'sh000001',
       'sz002344',
       'sz300159',
       'sh600717',
       'sh600332'
      ]   

results = []

http = Net::HTTP.new("hq.sinajs.cn")
GUs.each do |gu|
  response,body = http.get("/list=#{gu}")
  doc = response.body
  re = doc.scan(/.*\"(.*)\";/)
  array = CSV.parse(re[0][0])
  results << "#{gu}: #{array[0][3]}"
end

http2 = Net::HTTP.new('finance.yahoo.com')
response = http2.get('/webservice/v1/symbols/allcurrencies/quote')
xml = response.body
doc = Nokogiri::Slop(xml)

doc.list.resources.resource.each do |e|
  FXs.each do |f|                                                               
    fx = f + "=X"
    if e.xpath('field[@name="symbol"]').text() == fx
 price = e.xpath('field[@name="price"]').text()
      p =  fx == 'JPY=X' ? price : 1 / price.to_f
      results << format("%s: %.4f\n", f, p.to_f)
    end
  end
end

results.each {|e| puts e}     
  • 我现在关注的股票都给你了 (^^)
新手上路,请多包涵
新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进