bovespa-prices 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +9 -0
- data/LICENSE +22 -0
- data/README.md +59 -0
- data/Rakefile +2 -0
- data/bovespa-prices.gemspec +18 -0
- data/bovespa-prices.rb +36 -0
- data/spec/bovespa-prices_spec.rb +109 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Andrew S Aguiar
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Bovespa Prices
|
|
2
|
+
Bovespa-prices connects to Bovespa to get stock prices
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
Add this line to your application's Gemfile:
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
gem 'bovespa-prices'
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
```shell
|
|
13
|
+
bundle
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or install it yourself as:
|
|
17
|
+
```shell
|
|
18
|
+
gem install bovespa-prices
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
require 'bovespa-prices'
|
|
25
|
+
|
|
26
|
+
bovespa = Bovespa.new
|
|
27
|
+
|
|
28
|
+
# returns a Hash with Stock objects
|
|
29
|
+
results = bovespa.get(:VALE5, :GGBR4)
|
|
30
|
+
|
|
31
|
+
vale5 = results[:VALE5]
|
|
32
|
+
puts vale5.name
|
|
33
|
+
puts vale5.opening_price
|
|
34
|
+
puts vale5.min_price
|
|
35
|
+
puts vale5.max_price
|
|
36
|
+
puts vale5.average_price
|
|
37
|
+
puts vale5.last_price
|
|
38
|
+
puts vale5.variation
|
|
39
|
+
puts vale5.code
|
|
40
|
+
|
|
41
|
+
ggbr4 = results[:GGBR4]
|
|
42
|
+
puts ggbr4.name
|
|
43
|
+
puts ggbr4.opening_price
|
|
44
|
+
puts ggbr4.min_price
|
|
45
|
+
puts ggbr4.max_price
|
|
46
|
+
puts ggbr4.average_price
|
|
47
|
+
puts ggbr4.last_price
|
|
48
|
+
puts ggbr4.variation
|
|
49
|
+
puts ggbr4.code
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Contributing
|
|
54
|
+
|
|
55
|
+
1. Fork it
|
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
57
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
59
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../bovespa-prices', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ['Andrew S Aguiar']
|
|
6
|
+
gem.email = ['andrewaguiar6@gmail.com']
|
|
7
|
+
gem.description = 'bovespa-prices is a ruby gem that connects to bovespa to get stock prices'
|
|
8
|
+
gem.summary = 'bovespa-prices is a ruby gem that connects to bovespa to get stock prices'
|
|
9
|
+
gem.homepage = 'http://www.github.com/andrewaguiar/bovespa-prices'
|
|
10
|
+
gem.files = `git ls-files`.split($\)
|
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
13
|
+
gem.name = 'bovespa-prices'
|
|
14
|
+
gem.version = Bovespa::VERSION
|
|
15
|
+
|
|
16
|
+
gem.add_dependency 'httpclient'
|
|
17
|
+
gem.add_dependency 'nokogiri'
|
|
18
|
+
end
|
data/bovespa-prices.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'httpclient'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
|
|
4
|
+
class Bovespa
|
|
5
|
+
VERSION = "1.0.0"
|
|
6
|
+
|
|
7
|
+
class Stock
|
|
8
|
+
attr_accessor :code, :name, :date, :opening_price, :min_price, :max_price, :average_price, :last_price, :variation
|
|
9
|
+
|
|
10
|
+
def to_s
|
|
11
|
+
"#{@code} - '#{@name}' #{@opening_price} #{@min_price} #{@max_price} #{@average_price} #{@last_price} #{@variation}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def get *stock_codes
|
|
16
|
+
result = Hash.new
|
|
17
|
+
|
|
18
|
+
xml = Nokogiri.XML(HTTPClient.new.get_content("http://www.bmfbovespa.com.br/Pregao-Online/ExecutaAcaoAjax.asp?intEstado=1&CodigoPapel=#{URI.escape(stock_codes.join('|'))}"))
|
|
19
|
+
xml.search('Papel').each do |p|
|
|
20
|
+
st = Stock.new
|
|
21
|
+
st.name = p['Nome']
|
|
22
|
+
st.date = p['Data']
|
|
23
|
+
st.opening_price = p['Abertura'].gsub(',','.').to_f
|
|
24
|
+
st.min_price = p['Minimo'].gsub(',','.').to_f
|
|
25
|
+
st.max_price = p['Maximo'].gsub(',','.').to_f
|
|
26
|
+
st.average_price = p['Medio'].gsub(',','.').to_f
|
|
27
|
+
st.last_price = p['Ultimo'].gsub(',','.').to_f
|
|
28
|
+
st.variation = p['Oscilacao'].gsub(',','.').to_f
|
|
29
|
+
st.code = p['Codigo']
|
|
30
|
+
|
|
31
|
+
result[st.code.to_sym] = st
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
result
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require 'simplecov'
|
|
2
|
+
SimpleCov.start
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../../bovespa-prices', __FILE__)
|
|
5
|
+
|
|
6
|
+
describe Bovespa::Stock do
|
|
7
|
+
let(:stock) { Bovespa::Stock.new }
|
|
8
|
+
let(:stock_to_s) {
|
|
9
|
+
|
|
10
|
+
code = 'VALE5'
|
|
11
|
+
name = 'Vale'
|
|
12
|
+
opening_price = '50'
|
|
13
|
+
min_price = '49'
|
|
14
|
+
max_price = '51.4'
|
|
15
|
+
average_price = '50'
|
|
16
|
+
last_price = '50.45'
|
|
17
|
+
variation = '-2.45'
|
|
18
|
+
|
|
19
|
+
"#{code} - '#{name}' #{opening_price} #{min_price} #{max_price} #{average_price} #{last_price} #{variation}"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[:code, :name, :date, :opening_price, :min_price, :max_price, :average_price, :last_price, :variation].each do |p|
|
|
23
|
+
it "should respond to #{p}" do
|
|
24
|
+
stock.respond_to?(p).should == true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should respond to #{p}=" do
|
|
28
|
+
stock.respond_to?("#{p}=".to_sym).should == true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should show all informations about stock' do
|
|
33
|
+
code = 'VALE5'
|
|
34
|
+
name = 'Vale'
|
|
35
|
+
opening_price = '50'
|
|
36
|
+
min_price = '49'
|
|
37
|
+
max_price = '51.4'
|
|
38
|
+
average_price = '50'
|
|
39
|
+
last_price = '50.45'
|
|
40
|
+
variation = '-2.45'
|
|
41
|
+
|
|
42
|
+
st = Bovespa::Stock.new
|
|
43
|
+
st.code = 'VALE5'
|
|
44
|
+
st.name = 'Vale'
|
|
45
|
+
st.opening_price = '50'
|
|
46
|
+
st.min_price = '49'
|
|
47
|
+
st.max_price = '51.4'
|
|
48
|
+
st.average_price = '50'
|
|
49
|
+
st.last_price = '50.45'
|
|
50
|
+
st.variation = '-2.45'
|
|
51
|
+
|
|
52
|
+
st.to_s.include?('VALE5').should == true
|
|
53
|
+
st.to_s.include?('Vale').should == true
|
|
54
|
+
st.to_s.include?('50').should == true
|
|
55
|
+
st.to_s.include?('49').should == true
|
|
56
|
+
st.to_s.include?('51.4').should == true
|
|
57
|
+
st.to_s.include?('50').should == true
|
|
58
|
+
st.to_s.include?('50.45').should == true
|
|
59
|
+
st.to_s.include?('-2.45').should == true
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe Bovespa::Stock do
|
|
64
|
+
let(:xml_one){
|
|
65
|
+
'<?xml version="1.0"?>
|
|
66
|
+
<ComportamentoPapeis>
|
|
67
|
+
<Papel Codigo="VALE5" Nome="VALE PNA N1" Ibovespa="#" Data="31/08/2012 18:59:59" Abertura="32,88" Minimo="32,54" Maximo="33,24" Medio="32,61" Ultimo="33,04" Oscilacao="2,25"/>
|
|
68
|
+
</ComportamentoPapeis>'
|
|
69
|
+
}
|
|
70
|
+
let(:xml_two){
|
|
71
|
+
'<?xml version="1.0"?>
|
|
72
|
+
<ComportamentoPapeis>
|
|
73
|
+
<Papel Codigo="VALE5" Nome="VALE PNA N1" Ibovespa="#" Data="31/08/2012 18:59:59" Abertura="32,88" Minimo="32,54" Maximo="33,24" Medio="32,61" Ultimo="33,04" Oscilacao="2,25"/>
|
|
74
|
+
<Papel Codigo="RDCD3" Nome="REDECARD ON NM" Ibovespa="#" Data="31/08/2012 18:41:32" Abertura="33,88" Minimo="33,52" Maximo="33,88" Medio="33,65" Ultimo="33,56" Oscilacao="-0,71"/>
|
|
75
|
+
</ComportamentoPapeis>'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
it "should parse a xml with one stock from bovespa to one Stock" do
|
|
79
|
+
HTTPClient.stub(:get_content).and_return(xml_one)
|
|
80
|
+
|
|
81
|
+
result = Bovespa.new.get(:VALE5)
|
|
82
|
+
|
|
83
|
+
result.should_not be_empty
|
|
84
|
+
result.should be_a_kind_of Hash
|
|
85
|
+
result.size.should == 1
|
|
86
|
+
result.should have_key :VALE5
|
|
87
|
+
|
|
88
|
+
result[:VALE5].should be_a_kind_of Bovespa::Stock
|
|
89
|
+
result[:VALE5].to_s.should == "VALE5 - 'VALE PNA N1' 32.88 32.54 33.24 32.61 33.04 2.25"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should parse a xml with two stocks from bovespa to one Stock" do
|
|
93
|
+
HTTPClient.stub(:get_content).and_return(xml_two)
|
|
94
|
+
|
|
95
|
+
result = Bovespa.new.get(:VALE5, :RDCD3)
|
|
96
|
+
|
|
97
|
+
result.should_not be_empty
|
|
98
|
+
result.should be_a_kind_of Hash
|
|
99
|
+
result.size.should == 2
|
|
100
|
+
result.should have_key :VALE5
|
|
101
|
+
result.should have_key :RDCD3
|
|
102
|
+
|
|
103
|
+
result[:VALE5].should be_a_kind_of Bovespa::Stock
|
|
104
|
+
result[:VALE5].to_s.should == "VALE5 - 'VALE PNA N1' 32.88 32.54 33.24 32.61 33.04 2.25"
|
|
105
|
+
|
|
106
|
+
result[:RDCD3].should be_a_kind_of Bovespa::Stock
|
|
107
|
+
result[:RDCD3].to_s.should == "RDCD3 - 'REDECARD ON NM' 33.88 33.52 33.88 33.65 33.56 -0.71"
|
|
108
|
+
end
|
|
109
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bovespa-prices
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Andrew S Aguiar
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-09-02 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: httpclient
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: nokogiri
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
description: bovespa-prices is a ruby gem that connects to bovespa to get stock prices
|
|
47
|
+
email:
|
|
48
|
+
- andrewaguiar6@gmail.com
|
|
49
|
+
executables: []
|
|
50
|
+
extensions: []
|
|
51
|
+
extra_rdoc_files: []
|
|
52
|
+
files:
|
|
53
|
+
- .gitignore
|
|
54
|
+
- Gemfile
|
|
55
|
+
- LICENSE
|
|
56
|
+
- README.md
|
|
57
|
+
- Rakefile
|
|
58
|
+
- bovespa-prices.gemspec
|
|
59
|
+
- bovespa-prices.rb
|
|
60
|
+
- spec/bovespa-prices_spec.rb
|
|
61
|
+
homepage: http://www.github.com/andrewaguiar/bovespa-prices
|
|
62
|
+
licenses: []
|
|
63
|
+
post_install_message:
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
none: false
|
|
69
|
+
requirements:
|
|
70
|
+
- - ! '>='
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ! '>='
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 1.8.24
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 3
|
|
84
|
+
summary: bovespa-prices is a ruby gem that connects to bovespa to get stock prices
|
|
85
|
+
test_files:
|
|
86
|
+
- spec/bovespa-prices_spec.rb
|