Sha256: 96f4157af22265b2d5c120590863fffe0ab592f5b6c84b58e3848e07bacf8223

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'httpclient'
require 'nokogiri'

class Bovespa
	VERSION = "1.0.0"

	class Stock
		attr_accessor :code, :name, :date, :opening_price, :min_price, :max_price, :average_price, :last_price, :variation

		def to_s
			"#{@code} - '#{@name}' #{@opening_price} #{@min_price} #{@max_price} #{@average_price} #{@last_price} #{@variation}"
		end
	end

	def get *stock_codes
		result = Hash.new

		xml = Nokogiri.XML(HTTPClient.new.get_content("http://www.bmfbovespa.com.br/Pregao-Online/ExecutaAcaoAjax.asp?intEstado=1&CodigoPapel=#{URI.escape(stock_codes.join('|'))}"))
		xml.search('Papel').each do |p|
			st = Stock.new
			st.name = p['Nome']
			st.date = p['Data']
			st.opening_price = p['Abertura'].gsub(',','.').to_f
			st.min_price = p['Minimo'].gsub(',','.').to_f
			st.max_price = p['Maximo'].gsub(',','.').to_f
			st.average_price = p['Medio'].gsub(',','.').to_f
			st.last_price = p['Ultimo'].gsub(',','.').to_f
			st.variation = p['Oscilacao'].gsub(',','.').to_f
			st.code = p['Codigo']

			result[st.code.to_sym] = st
		end

		result
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bovespa-prices-1.0.0 bovespa-prices.rb