ifqar 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5da6aeac0267d3a95b2b002fa02d906b3a2dfda5
4
+ data.tar.gz: 44ddcc3ae1c60e8c5b982e6e7dc35773d5c167ed
5
+ SHA512:
6
+ metadata.gz: 18853eb92f28454cfef648554abb96ed5a9c6843aa68847feb19966973095e720b66250615ff32ecaa89580504cc15478c7d979e0168ca7e32919e63b00cc3fc
7
+ data.tar.gz: 2652a0a28e730ba2287874e6fb4e0c7edd9b175396da7670a33b2febd804ab2f77391689e9705a1c49ab46a26b30dc4118863f146ebb9fffbc897c7a03792435
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ Style/HashSyntax:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ifqar.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Christian Hein
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Ifqar
2
+
3
+ Investment Funds Quoter Argentina is a ruby client that retrieves funds stats
4
+ from [cafci.org.ar](http://www.cafci.org.ar/)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ifqar'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ifqar
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'ifqar'
26
+
27
+ date = Date.parse('14-03-2017')
28
+ type = :EQUITY
29
+
30
+ quoter = Ifqar::FundQuoter.new
31
+ stats = quoter.stats(date, type)
32
+
33
+ stats.funds_quotes.each do |fund_quote|
34
+ puts [fund_quote.fund.name, fund_quote.share_value].join(': ')
35
+ end
36
+ ```
37
+
38
+
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chrishein/ifqar.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ifqar"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ifqar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ifqar'
8
+ spec.version = Ifqar::VERSION
9
+ spec.authors = ['Christian Hein']
10
+ spec.email = ['chrishein@gmail.com']
11
+
12
+ spec.summary = 'Argentina Investment Funds Quotess client.'
13
+ spec.description = 'Get quotes for Investment Funds in Argentina from cafci.org.ar.'
14
+ spec.homepage = 'https://github.com/chrishein/ifqar'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.1'
25
+ spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
31
+ spec.add_development_dependency 'webmock', '~> 2.3', '>= 2.3.2'
32
+ end
@@ -0,0 +1,6 @@
1
+ require 'ifqar/version'
2
+ require 'ifqar/daily_funds_stats'
3
+ require 'ifqar/fund_quote'
4
+ require 'ifqar/fund_quoter'
5
+ require 'ifqar/fund'
6
+ require 'ifqar/stats_deserializer'
@@ -0,0 +1,11 @@
1
+ module Ifqar
2
+ # Daily Funds Stats
3
+ class DailyFundsStats
4
+ attr_accessor :date, :funds_quotes
5
+
6
+ def initialize(date)
7
+ @date = date
8
+ @funds_quotes = []
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Ifqar
2
+ # Fund represents an Investment Fund
3
+ class Fund
4
+ attr_accessor :name, :type
5
+
6
+ def initialize(name, type)
7
+ @name = name
8
+ @type = type
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Ifqar
2
+ # Fund Quote is an Investment Fund Quote for a given date, with
3
+ # amount of shares, shave_value and net asset value
4
+ class FundQuote
5
+ attr_accessor :fund, :date, :shares, :share_value, :net_asset_value
6
+
7
+ def initialize(fund, date, shares, share_value, net_asset_value)
8
+ @fund = fund
9
+ @date = date
10
+ @shares = shares
11
+ @share_value = share_value
12
+ @net_asset_value = net_asset_value
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,64 @@
1
+ require 'rest-client'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module Ifqar
6
+ # Fund Quoter is the client that retrieves quotes from cafci.org.ar
7
+ class FundQuoter
8
+ FUND_TYPE = {
9
+ :EQUITY => { :id => 1, :name => 'Renta Variable' },
10
+ :FIXED_INCOME => { :id => 2, :name => 'Renta Fija' },
11
+ :MONEY_MARKET => { :id => 3, :name => 'Mercado de Dinero' },
12
+ :BALANCED => { :id => 4, :name => 'Renta Mixta' }
13
+ }.freeze
14
+
15
+ HEADERS = {
16
+ :multipart => true,
17
+ :referer => 'http://www.cafci.org.ar/scripts/cfn_EstadisticasVCP.html'
18
+ }.freeze
19
+
20
+ SET_PARAMS_URL = 'http://www.cafci.org.ar/Scripts/cfn_EstadisticaVCPXMLSet.asp'.freeze
21
+ QUERY_URL = 'http://www.cafci.org.ar/Scripts/cfn_PlanillaDiariaXMLList.asp'.freeze
22
+
23
+ def initialize
24
+ @daily_stats = {}
25
+ end
26
+
27
+ def stats(date, type)
28
+ date_str = date.strftime('%Y-%m-%d')
29
+ stats = cached_stats(date_str, type)
30
+ if stats.nil?
31
+ stats = query_service(date, type)
32
+ @daily_stats[date_str] = {} if @daily_stats[date_str].nil?
33
+ @daily_stats[date_str][type] = stats
34
+ end
35
+ stats
36
+ end
37
+
38
+ def query_service(date, type)
39
+ payload = payload_builder(date, type)
40
+ response = RestClient.post(SET_PARAMS_URL, { :query => payload }, HEADERS)
41
+ response = RestClient.post(QUERY_URL, nil, HEADERS.merge(:cookies => response.cookies))
42
+
43
+ StatsDeserializer.deserialze(date, FUND_TYPE[type][:name], response.body)
44
+ end
45
+
46
+ def payload_builder(date, type)
47
+ Nokogiri::XML::Builder.new do |xml|
48
+ xml.Coleccion do
49
+ xml.Parametros do
50
+ xml.TRentaI FUND_TYPE[type][:id]
51
+ xml.TRentaN URI.encode(FUND_TYPE[type][:name])
52
+ xml.Fecha date.strftime('%Y-%m-%d')
53
+ xml.Separador 'P'
54
+ end
55
+ end
56
+ end.doc.root.serialize(save_with: 0)
57
+ end
58
+
59
+ def cached_stats(date, type)
60
+ return nil if @daily_stats[date].nil? || @daily_stats[date][type].nil?
61
+ @daily_stats[date][type]
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,36 @@
1
+ require 'nokogiri'
2
+
3
+ module Ifqar
4
+ # Convert XML stats to DailyFundsStats
5
+ class StatsDeserializer
6
+ QUOTES_XPATH = "//Dato[Espacios = '3']".freeze
7
+
8
+ def self.deserialze(date, type, xml)
9
+ xml_doc = Nokogiri::XML(xml)
10
+
11
+ daily_stats = DailyFundsStats.new(date)
12
+ xml_doc.xpath(QUOTES_XPATH).each do |data|
13
+ daily_stats.funds_quotes << quote_builder(date, type, data)
14
+ end
15
+ daily_stats
16
+ end
17
+
18
+ def self.quote_builder(date, type, data_node)
19
+ name = data_node.xpath('Nombre').text
20
+ shares = parse_int(data_node.xpath('QCP').text)
21
+ share_value = parse_float(data_node.xpath('VCP').text) / 1000
22
+ net_asset_value = parse_int(data_node.xpath('PN').text)
23
+
24
+ fund = Fund.new(name, type)
25
+ FundQuote.new(fund, date, shares, share_value, net_asset_value)
26
+ end
27
+
28
+ def self.parse_float(text)
29
+ text.delete('.').sub(',', '.').to_f
30
+ end
31
+
32
+ def self.parse_int(text)
33
+ text.delete('.').sub(',', '.').to_i
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Ifqar
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ifqar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Hein
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: nokogiri
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.6.8
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.6'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.6.8
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.14'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.14'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: vcr
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.0'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.0.3
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.0'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 3.0.3
115
+ - !ruby/object:Gem::Dependency
116
+ name: webmock
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '2.3'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.3.2
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.3'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 2.3.2
135
+ description: Get quotes for Investment Funds in Argentina from cafci.org.ar.
136
+ email:
137
+ - chrishein@gmail.com
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - ".gitignore"
143
+ - ".rspec"
144
+ - ".rubocop.yml"
145
+ - ".travis.yml"
146
+ - Gemfile
147
+ - LICENSE.txt
148
+ - README.md
149
+ - Rakefile
150
+ - bin/console
151
+ - bin/setup
152
+ - ifqar.gemspec
153
+ - lib/ifqar.rb
154
+ - lib/ifqar/daily_funds_stats.rb
155
+ - lib/ifqar/fund.rb
156
+ - lib/ifqar/fund_quote.rb
157
+ - lib/ifqar/fund_quoter.rb
158
+ - lib/ifqar/stats_deserializer.rb
159
+ - lib/ifqar/version.rb
160
+ homepage: https://github.com/chrishein/ifqar
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.4.8
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Argentina Investment Funds Quotess client.
184
+ test_files: []