currency-rate 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/adapter.rb +14 -0
- data/lib/btc_adapter.rb +7 -1
- data/lib/btc_adapters/bitfinex_adapter.rb +1 -1
- data/lib/btc_adapters/bitstamp_adapter.rb +1 -1
- data/lib/btc_adapters/btce_adapter.rb +1 -1
- data/lib/btc_adapters/huobi_adapter.rb +1 -1
- data/lib/btc_adapters/okcoin_adapter.rb +1 -1
- data/lib/currency_rate.rb +3 -3
- data/lib/fiat_adapter.rb +7 -1
- data/lib/fiat_adapters/fixer_adapter.rb +2 -2
- data/lib/fiat_adapters/yahoo_adapter.rb +3 -3
- data/spec/lib/btc_adapter_spec.rb +1 -1
- data/spec/lib/btc_adapters/bitfinex_adapter_spec.rb +2 -2
- data/spec/lib/btc_adapters/bitstamp_adapter_spec.rb +3 -3
- data/spec/lib/btc_adapters/btcchina_adapter_spec.rb +1 -1
- data/spec/lib/btc_adapters/btce_adapter_spec.rb +4 -4
- data/spec/lib/btc_adapters/huobi_adapter_spec.rb +2 -2
- data/spec/lib/btc_adapters/kraken_adapter_spec.rb +2 -2
- data/spec/lib/btc_adapters/localbitcoins_adapter_spec.rb +1 -1
- data/spec/lib/btc_adapters/okcoin_adapter_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f13270a16a551a2dd99d249aa2d17d6c001383a7
|
4
|
+
data.tar.gz: 2a8ef8d2c5ecadbbc80d21dd0446a5c447de338b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 978abb25b8a76169a863739ca9b162a9f2ca4e6a798ba33e4884925f7df435917ac4d33302b032b09a56d0136387838dd7786ab08ccd601c7da6553728056e7c
|
7
|
+
data.tar.gz: 307a3d0240fb7d69895f6e1ca0b215943711e23a52927ac1f06339537949e19a09289cdfb65d71c6dfbdc781b4775f010942b338bddf5eea685cd8955d642686
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/adapter.rb
CHANGED
@@ -46,5 +46,19 @@ module CurrencyRate
|
|
46
46
|
def rate_to_f(rate)
|
47
47
|
rate ? rate.to_f : raise(CurrencyNotSupported)
|
48
48
|
end
|
49
|
+
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def _invert_rate(rate)
|
54
|
+
r = (BigDecimal.new('1')/BigDecimal.new(rate.to_s))
|
55
|
+
r = r.round(decimal_precision) if decimal_precision
|
56
|
+
r
|
57
|
+
end
|
58
|
+
|
59
|
+
def decimal_precision
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
49
63
|
end
|
50
64
|
end
|
data/lib/btc_adapter.rb
CHANGED
data/lib/currency_rate.rb
CHANGED
@@ -31,13 +31,13 @@ module CurrencyRate
|
|
31
31
|
else
|
32
32
|
rate_from = get(adapter_name, anchor_currency, from)
|
33
33
|
rate_to = get(adapter_name, anchor_currency, to )
|
34
|
-
rate_to.
|
34
|
+
BigDecimal.new(rate_to.to_s)/BigDecimal.new(rate_from.to_s)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.convert(adapter_name, amount:, from:, to:, anchor_currency: nil)
|
39
|
-
result = amount*get(adapter_name, from, to, anchor_currency: nil)
|
40
|
-
to == 'BTC' ? result : result.round(2)
|
39
|
+
result = BigDecimal.new(amount.to_s)*BigDecimal.new(get(adapter_name, from, to, anchor_currency: nil).to_s)
|
40
|
+
to == 'BTC' ? result.round(9) : result.round(2)
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
data/lib/fiat_adapter.rb
CHANGED
@@ -3,7 +3,7 @@ module CurrencyRate
|
|
3
3
|
class FiatAdapter < Adapter
|
4
4
|
|
5
5
|
BigDecimal.mode BigDecimal::ROUND_MODE, :banker
|
6
|
-
|
6
|
+
#@@decimal_precision = 2
|
7
7
|
|
8
8
|
def rate_for(from,to)
|
9
9
|
super
|
@@ -11,6 +11,12 @@ module CurrencyRate
|
|
11
11
|
invert_rate(from,to,rate)
|
12
12
|
end
|
13
13
|
|
14
|
+
private
|
15
|
+
|
16
|
+
def decimal_precision
|
17
|
+
2
|
18
|
+
end
|
19
|
+
|
14
20
|
end
|
15
21
|
|
16
22
|
end
|
@@ -11,12 +11,12 @@ module CurrencyRate
|
|
11
11
|
raise CurrencyNotSupported unless rates
|
12
12
|
rate = rates["rates"][currency1] || rates["rates"][currency2]
|
13
13
|
raise CurrencyNotSupported unless rate
|
14
|
-
rate.round(
|
14
|
+
BigDecimal.new(rate.to_s).round(decimal_precision)
|
15
15
|
end
|
16
16
|
|
17
17
|
def invert_rate(from,to,rate)
|
18
18
|
if (to == 'USD' || to == 'EUR')
|
19
|
-
(
|
19
|
+
_invert_rate(rate)
|
20
20
|
else
|
21
21
|
rate
|
22
22
|
end
|
@@ -22,7 +22,7 @@ module CurrencyRate
|
|
22
22
|
|
23
23
|
def invert_rate(from,to,rate)
|
24
24
|
if to == 'USD'
|
25
|
-
(
|
25
|
+
_invert_rate(rate)
|
26
26
|
else
|
27
27
|
rate
|
28
28
|
end
|
@@ -36,8 +36,8 @@ module CurrencyRate
|
|
36
36
|
rates.find { |x| x['id'] == "#{CROSS_RATE_CURRENCY}#{currency1.upcase}" }
|
37
37
|
end
|
38
38
|
raise CurrencyNotSupported unless rate
|
39
|
-
rate = rate['Rate']
|
40
|
-
rate.round(
|
39
|
+
rate = BigDecimal.new(rate['Rate'])
|
40
|
+
rate.round(decimal_precision)
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -21,7 +21,7 @@ RSpec.describe CurrencyRate::BtcAdapter do
|
|
21
21
|
it "inverts currency rate when needed" do
|
22
22
|
allow(SomeExchangeAdapter.instance).to receive(:fetch_rates!)
|
23
23
|
@exchange_adapter = SomeExchangeAdapter.instance
|
24
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
24
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.001333333)
|
25
25
|
end
|
26
26
|
|
27
27
|
|
@@ -16,9 +16,9 @@ RSpec.describe CurrencyRate::BitfinexAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(763.0)
|
19
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.001310616)
|
20
20
|
expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(5.5105)
|
21
|
-
expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.
|
21
|
+
expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.181471736)
|
22
22
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
23
23
|
end
|
24
24
|
|
@@ -16,10 +16,10 @@ RSpec.describe CurrencyRate::BitstampAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(751.97)
|
19
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.00132984)
|
20
20
|
expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(674.5)
|
21
|
-
expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.
|
22
|
-
expect(@exchange_adapter.rate_for('USD', 'EUR')).to eq(0.
|
21
|
+
expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.00148258)
|
22
|
+
expect(@exchange_adapter.rate_for('USD', 'EUR')).to eq(0.900884669)
|
23
23
|
expect(@exchange_adapter.rate_for('EUR', 'USD')).to eq(1.11002)
|
24
24
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
25
25
|
end
|
@@ -16,7 +16,7 @@ RSpec.describe CurrencyRate::BTCChinaAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(4785.55)
|
19
|
-
expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.000208962)
|
20
20
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
21
21
|
end
|
22
22
|
|
@@ -16,13 +16,13 @@ RSpec.describe CurrencyRate::BtceAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(723.872)
|
19
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.00138146)
|
20
20
|
expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(665.022)
|
21
|
-
expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.
|
21
|
+
expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.00150371)
|
22
22
|
expect(@exchange_adapter.rate_for('USD', 'RUB')).to eq(60.5)
|
23
|
-
expect(@exchange_adapter.rate_for('RUB', 'USD')).to eq(0.
|
23
|
+
expect(@exchange_adapter.rate_for('RUB', 'USD')).to eq(0.016528926)
|
24
24
|
expect(@exchange_adapter.rate_for('EUR', 'RUB')).to eq(65.63)
|
25
|
-
expect(@exchange_adapter.rate_for('RUB', 'EUR')).to eq(0.
|
25
|
+
expect(@exchange_adapter.rate_for('RUB', 'EUR')).to eq(0.015236934)
|
26
26
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
27
27
|
end
|
28
28
|
|
@@ -16,9 +16,9 @@ RSpec.describe CurrencyRate::HuobiAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(4791.5)
|
19
|
-
expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.000208703)
|
20
20
|
expect(@exchange_adapter.rate_for('LTC', 'CNY')).to eq(34.25)
|
21
|
-
expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.
|
21
|
+
expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.02919708)
|
22
22
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
23
23
|
end
|
24
24
|
|
@@ -16,9 +16,9 @@ RSpec.describe CurrencyRate::KrakenAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(755.15)
|
19
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.00132424)
|
20
20
|
expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(671.215)
|
21
|
-
expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.
|
21
|
+
expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.001489836)
|
22
22
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
23
23
|
end
|
24
24
|
|
@@ -16,7 +16,7 @@ RSpec.describe CurrencyRate::LocalbitcoinsAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(591.95)
|
19
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(BigDecimal.new('0.001689332'))
|
20
20
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
21
21
|
end
|
22
22
|
|
@@ -16,14 +16,14 @@ RSpec.describe CurrencyRate::OkcoinAdapter do
|
|
16
16
|
|
17
17
|
it "finds the rate for currency code" do
|
18
18
|
expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(769.05)
|
19
|
-
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.
|
19
|
+
expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.001300306)
|
20
20
|
expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(5113.0)
|
21
|
-
expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.
|
21
|
+
expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.000195580)
|
22
22
|
|
23
23
|
expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(5.661)
|
24
|
-
expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.
|
24
|
+
expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.176647235)
|
25
25
|
expect(@exchange_adapter.rate_for('LTC', 'CNY')).to eq(37.68)
|
26
|
-
expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.
|
26
|
+
expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.026539278)
|
27
27
|
expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
|
28
28
|
end
|
29
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currency-rate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Snitko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: satoshi-unit
|