bloomberg_currency 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/README.md +46 -8
- data/Rakefile +1 -0
- data/bloomberg_currency.gemspec +6 -4
- data/lib/bloomberg_currency.rb +4 -2
- data/lib/bloomberg_currency/api/host.rb +2 -1
- data/lib/bloomberg_currency/api/site.rb +41 -36
- data/lib/bloomberg_currency/quote.rb +20 -0
- data/lib/bloomberg_currency/quote_detail.rb +29 -0
- data/lib/bloomberg_currency/version.rb +3 -2
- metadata +38 -16
- data/lib/bloomberg_currency/models/quote.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5750a9ea831b7ce49a0e34ea6f50dd02e055a84c
|
4
|
+
data.tar.gz: d8d18e027f2fb8af17eecb69272e7eba0db81dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae8f01e406f1ad92d792eaa7a3e4bc90faa3f39b75cace02be43b9fd1226c9c9b2e71e7ac5eb16b1730c1c4687839f79d869f9cde3b1fa7c449a00911a7db1b
|
7
|
+
data.tar.gz: fa004d8549d9606417bc50b3d5230ac8eeabf7897e3f49750bd9febaa98980831ee57a059560ffa40db49cc7e9cf10bf7bc6d4f289ae93faaff816eb7e45111f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/sebasjimenez10/bloomberg_currency.svg?branch=master)](https://travis-ci.org/sebasjimenez10/bloomberg_currency) [![Code Climate](https://codeclimate.com/github/sebasjimenez10/bloomberg_currency/badges/gpa.svg)](https://codeclimate.com/github/sebasjimenez10/bloomberg_currency) [![Test Coverage](https://codeclimate.com/github/sebasjimenez10/bloomberg_currency/badges/coverage.svg)](https://codeclimate.com/github/sebasjimenez10/bloomberg_currency/coverage) [![Issue Count](https://codeclimate.com/github/sebasjimenez10/bloomberg_currency/badges/issue_count.svg)](https://codeclimate.com/github/sebasjimenez10/bloomberg_currency)
|
4
4
|
|
5
|
-
Bloomberg Currency provides an easy-to-use API to pull currency exchange rates from the Bloomberg
|
5
|
+
Bloomberg Currency provides an easy-to-use API to pull currency exchange rates from the Bloomberg site. If you would like to test out this gem before including it into your project, feel free to clone it, bundle it and run `bin/console` for an interactive prompt.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,19 +22,57 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
*NOTE*: From version `0.1.0` to `1.0.0` there are mayor breaking changes. Please make sure you read the docs before installing/upgrading to the newest version.
|
26
26
|
|
27
|
+
The gem usability has been improved in version 1.0. Now you only need to create an instance of the class `BC::Quote`, passing the two currencies you'd like to get information about, like this:
|
28
|
+
|
29
|
+
```
|
30
|
+
quote = BC::Quote.new('USD', 'EUR')
|
31
|
+
=> #<BC::Quote:0x007fe92c297670 @price=0.8156, @datetime=#<DateTime: 2018-01-16T17:13:00-05:00 ((2458135j,79980s,0n),-18000s,2299161j)>, @detail=#<BC::QuoteDetail:0x007fe92c3ae8d8 @open=0.8157, @day_range=0.8156..0.8159, @previous_close=0.8157, @last_52_weeks_range=0.8133..0.9529, @ytd_return=-2.14>, @available=true>
|
27
32
|
```
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
|
34
|
+
Then the quote object offers a few accessor methods:
|
35
|
+
|
36
|
+
- `price`: Returns a float price
|
37
|
+
- `datetime`: Returns the date time when the price was captured
|
38
|
+
- `detail`: Returns an object of the class BC::QuoteDetail which encapsulate the details of the quote. Will be explained later on.
|
39
|
+
- `available?`: Return true or false if the exchange is available or not.
|
40
|
+
|
41
|
+
|
42
|
+
The `BC::QuoteDetail` class offers the following methods:
|
43
|
+
|
44
|
+
- `open`: Returns the value in which the currency opened.
|
45
|
+
- `day_range`: Returns the day range up until the moment the quote is generated.
|
46
|
+
- `previous_close`: Returns the value where the exchange closed last day.
|
47
|
+
- `last_52_weeks_range`: Returns the range od the last 52 weeks.
|
48
|
+
- `ytd_return`: Returns the YTD percentage.
|
49
|
+
|
50
|
+
|
51
|
+
*NOTE*: When the some of the markets close, the `open` and `day_range` attributes on the Bloomberg site aren't displayed. So those attributes may not be present if the market is closed. But the quote may still be available.
|
52
|
+
|
53
|
+
## Examples
|
54
|
+
|
55
|
+
Getting information about the USD and EUR exchange:
|
56
|
+
|
57
|
+
```
|
58
|
+
quote = BC::Quote.new('USD', 'EUR')
|
59
|
+
quote.price
|
60
|
+
=> 0.8147
|
61
|
+
|
62
|
+
quote.datetime
|
63
|
+
=> #<DateTime: 2018-01-16T14:35:00-05:00 ((2458135j,70500s,0n),-18000s,2299161j)>
|
64
|
+
|
65
|
+
quote.detail
|
66
|
+
=> #<BC::QuoteDetail:0x007faadd9fb868 @open=0.8154, @day_range=0.8143..0.8199, @previous_close=0.8154, @last_52_weeks_range=0.8133..0.9529, @ytd_return=-1.91>
|
67
|
+
|
68
|
+
quote.available?
|
69
|
+
=> true
|
70
|
+
|
31
71
|
```
|
32
|
-
As you could notice it will return a Quote object. This object contains three main attributes: `price`, `price_datetime` and `quote_details`.
|
33
|
-
Out of those three attributes, the `quote_details` attribute contains a hash, here's an example: `{:open=>"0.9180", :day_range=>"0.9156 - 0.9233", :previous_close=>"0.9180", :"52wk_range"=>"0.8612 - 0.9496", :ytd_return=>"0.10%"}`
|
34
72
|
|
35
73
|
## Development
|
36
74
|
|
37
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
76
|
|
39
77
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
78
|
|
data/Rakefile
CHANGED
data/bloomberg_currency.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'bloomberg_currency/version'
|
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.name = 'bloomberg_currency'
|
10
|
-
spec.version =
|
10
|
+
spec.version = BC::VERSION
|
11
11
|
spec.authors = ['Sebastian Jimenez Velez']
|
12
12
|
spec.email = ['sebasjimenezv@gmail.com']
|
13
13
|
|
@@ -37,7 +37,9 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency 'rake', '~> 10.0'
|
38
38
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
39
|
spec.add_development_dependency 'simplecov', '~> 0.11'
|
40
|
-
spec.add_development_dependency '
|
41
|
-
spec.add_development_dependency '
|
42
|
-
spec.add_development_dependency '
|
40
|
+
spec.add_development_dependency 'rubocop', '~> 0.49.0'
|
41
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.0'
|
42
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.5.1'
|
43
|
+
|
44
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
|
43
45
|
end
|
data/lib/bloomberg_currency.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'bloomberg_currency/version'
|
3
4
|
require 'bloomberg_currency/api/site'
|
4
5
|
require 'bloomberg_currency/api/host'
|
5
|
-
require 'bloomberg_currency/
|
6
|
+
require 'bloomberg_currency/quote'
|
7
|
+
require 'bloomberg_currency/quote_detail'
|
6
8
|
|
7
9
|
# Main Gem Module
|
8
|
-
module
|
10
|
+
module BC
|
9
11
|
end
|
@@ -1,57 +1,62 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'open-uri'
|
3
4
|
require 'nokogiri'
|
4
5
|
require 'bigdecimal'
|
5
6
|
|
6
|
-
module
|
7
|
+
module BC
|
7
8
|
module API
|
8
9
|
# Implements site scrapping
|
9
10
|
class Site
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
private
|
11
|
+
class << self
|
12
|
+
def quote(currency_one, currency_two)
|
13
|
+
process(currency_one, currency_two)
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
site = load_site(currency_one, currency_two)
|
18
|
-
parse(site)
|
19
|
-
end
|
16
|
+
private
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
def process(currency_one, currency_two)
|
19
|
+
site = load_site(currency_one, currency_two)
|
20
|
+
parse(site)
|
21
|
+
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def load_site(currency_one, currency_two)
|
24
|
+
file = open("#{BC::API::Host::URL}#{currency_one}#{currency_two}:CUR")
|
25
|
+
Nokogiri::HTML(file)
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def parse(document)
|
29
|
+
parse_quote(document)
|
30
|
+
rescue
|
31
|
+
{ price: nil, datetime: nil, detail: nil, available: false }
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
def parse_quote(document)
|
35
|
+
price_container = document.xpath("//div[contains(@class, 'price-container')]")
|
36
|
+
detailed_quote_container = document.xpath("//div[contains(@class, 'detailed-quote')]")
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
quote_details_hash = quote_details(detailed_quote_container)
|
38
|
+
price_element = price_container.xpath("//div[@class='price']")
|
39
|
+
price_datetime_element = price_container.xpath("//div[@class='price-datetime']")
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
price = price_element.text.strip.tr(',', '').to_f
|
42
|
+
datetime = DateTime.strptime(price_datetime_element.text.strip, 'As of %H:%M %p %z %m/%d/%Y')
|
43
|
+
details_hash = quote_details(detailed_quote_container)
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
"//div[contains(@class, 'cell') and contains(@class, 'cell__mobile-basic')]"
|
47
|
-
)
|
45
|
+
{ price: price, datetime: datetime, detail: BC::QuoteDetail.new(details_hash), available: true }
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def quote_details(container)
|
49
|
+
detail_elements = container.xpath("//div[@class='data-table data-table_detailed']").xpath(
|
50
|
+
"//div[contains(@class, 'cell') and contains(@class, 'cell__mobile-basic')]"
|
51
|
+
)
|
52
|
+
|
53
|
+
details_hash = {}
|
54
|
+
details_matrix = detail_elements.map { |a| a.text.strip.split(' ') }
|
55
|
+
details_matrix.each do |key_value_array|
|
56
|
+
details_hash[key_value_array[0].downcase.tr(' ', '_').to_sym] = key_value_array[1]
|
57
|
+
end
|
58
|
+
details_hash
|
53
59
|
end
|
54
|
-
details_hash
|
55
60
|
end
|
56
61
|
end
|
57
62
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BC
|
4
|
+
# Quote Information Class
|
5
|
+
class Quote
|
6
|
+
attr_accessor :price, :datetime, :detail, :available
|
7
|
+
def initialize(currency_one, currency_two)
|
8
|
+
result = BC::API::Site.quote(currency_one, currency_two)
|
9
|
+
|
10
|
+
@price = result[:price]
|
11
|
+
@datetime = result[:datetime]
|
12
|
+
@detail = result[:detail]
|
13
|
+
@available = result[:available]
|
14
|
+
end
|
15
|
+
|
16
|
+
def available?
|
17
|
+
available
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BC
|
4
|
+
# Quote Details Class
|
5
|
+
class QuoteDetail
|
6
|
+
attr_accessor :open, :day_range, :previous_close, :last_52_weeks_range, :ytd_return
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@open = process_float(attributes[:open])
|
10
|
+
@day_range = process_range(attributes[:day_range])
|
11
|
+
@previous_close = process_float(attributes[:previous_close])
|
12
|
+
@last_52_weeks_range = process_range(attributes[:"52wk_range"])
|
13
|
+
@ytd_return = process_float(attributes[:ytd_return])
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def process_range(range)
|
19
|
+
return unless range
|
20
|
+
edges = range.tr(',', '').strip.split('-')
|
21
|
+
edges[0].to_f..edges[1].to_f
|
22
|
+
end
|
23
|
+
|
24
|
+
def process_float(float)
|
25
|
+
return unless float
|
26
|
+
float.tr(',', '').to_f
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bloomberg_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Jimenez Velez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,53 +67,73 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.11'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.49.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.49.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
76
90
|
- - ">="
|
77
91
|
- !ruby/object:Gem::Version
|
78
|
-
version: 1.
|
92
|
+
version: 1.0.0
|
79
93
|
type: :development
|
80
94
|
prerelease: false
|
81
95
|
version_requirements: !ruby/object:Gem::Requirement
|
82
96
|
requirements:
|
83
97
|
- - "~>"
|
84
98
|
- !ruby/object:Gem::Version
|
85
|
-
version: '1.
|
99
|
+
version: '1.0'
|
86
100
|
- - ">="
|
87
101
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
102
|
+
version: 1.0.0
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
104
|
+
name: pry-byebug
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
107
|
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
109
|
+
version: 3.5.1
|
96
110
|
type: :development
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
114
|
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
116
|
+
version: 3.5.1
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
118
|
+
name: nokogiri
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - "~>"
|
108
122
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.
|
110
|
-
|
123
|
+
version: '1.6'
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.6.8
|
127
|
+
type: :runtime
|
111
128
|
prerelease: false
|
112
129
|
version_requirements: !ruby/object:Gem::Requirement
|
113
130
|
requirements:
|
114
131
|
- - "~>"
|
115
132
|
- !ruby/object:Gem::Version
|
116
|
-
version: 1.
|
133
|
+
version: '1.6'
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.6.8
|
117
137
|
description: Provides an easy to use API to get currency rates data from the Bloomberg
|
118
138
|
website
|
119
139
|
email:
|
@@ -122,6 +142,7 @@ executables: []
|
|
122
142
|
extensions: []
|
123
143
|
extra_rdoc_files: []
|
124
144
|
files:
|
145
|
+
- ".byebug_history"
|
125
146
|
- ".gitignore"
|
126
147
|
- ".rspec"
|
127
148
|
- ".rubocop.yml"
|
@@ -139,7 +160,8 @@ files:
|
|
139
160
|
- lib/bloomberg_currency.rb
|
140
161
|
- lib/bloomberg_currency/api/host.rb
|
141
162
|
- lib/bloomberg_currency/api/site.rb
|
142
|
-
- lib/bloomberg_currency/
|
163
|
+
- lib/bloomberg_currency/quote.rb
|
164
|
+
- lib/bloomberg_currency/quote_detail.rb
|
143
165
|
- lib/bloomberg_currency/version.rb
|
144
166
|
homepage: https://github.com/sebasjimenez10/bloomberg_currency
|
145
167
|
licenses:
|
@@ -162,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
184
|
version: '0'
|
163
185
|
requirements: []
|
164
186
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.6.11
|
166
188
|
signing_key:
|
167
189
|
specification_version: 4
|
168
190
|
summary: Bloomberg Currency helps you pull currency rates data from the Bloomberg
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module BloombergCurrency
|
3
|
-
module Models
|
4
|
-
# Quote Information
|
5
|
-
class Quote
|
6
|
-
attr_accessor :price, :price_datetime, :quote_details
|
7
|
-
def initialize(hash)
|
8
|
-
@price = hash[:price]
|
9
|
-
@price_datetime = hash[:price_datetime]
|
10
|
-
@quote_details = hash[:quote_details]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|