currency-rate 1.5.2 → 1.7.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.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/Gemfile.lock +68 -0
- data/README.md +2 -2
- data/Rakefile +12 -3
- data/currency-rate.gemspec +1 -1
- data/lib/adapter.rb +7 -2
- data/lib/adapters/crypto/bitfinex_adapter.rb +2 -1
- data/lib/adapters/crypto/hit_btc_adapter.rb +61 -0
- data/lib/adapters/crypto/huobi_adapter.rb +16 -8
- data/lib/adapters/crypto/kraken_adapter.rb +4 -4
- data/lib/adapters/crypto/paxful_adapter.rb +18 -0
- data/lib/adapters/crypto/poloniex_adapter.rb +33 -0
- data/lib/adapters/crypto/yadio_adapter.rb +19 -0
- data/lib/configuration.rb +1 -2
- data/lib/currency_rate.rb +1 -0
- data/lib/currency_rate/version.rb +1 -1
- data/lib/exceptions.rb +9 -0
- data/lib/fetcher.rb +3 -1
- data/lib/storage/file_storage.rb +2 -2
- data/lib/synchronizer.rb +6 -3
- metadata +11 -7
- data/bin/rake +0 -29
- data/bin/rspec +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db91dd121b519bd89adba8d9576c0746792e5a9e40206347284ed4fc9acc3089
|
4
|
+
data.tar.gz: ae3c3b6b260e4e202d25e602fc215ff7f2f55837a8b0e355da6d8e3c565961b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dbceacbf49cfb2d1f06174e443748ae6fced938b1ab2504e2a213d437afad3bf0cb822cd08041675e69fb55b9abc7e108c7433ed0c9e19621c9a17ab9f1da0c
|
7
|
+
data.tar.gz: 7fa1c6d94d9c34f9fd3ce672e044b24ee30ca081bda69bd19354902bd8df902bb6f5e073aac0525714f30d6d01bad1c7bb2cf21c835ebe278d457277e3760588
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
currency-rate (1.7.0)
|
5
|
+
http (>= 4.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
byebug (11.0.1)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
domain_name (0.5.20190701)
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
18
|
+
ffi (1.13.1)
|
19
|
+
ffi-compiler (1.0.1)
|
20
|
+
ffi (>= 1.0.0)
|
21
|
+
rake
|
22
|
+
hashdiff (1.0.0)
|
23
|
+
http (4.4.1)
|
24
|
+
addressable (~> 2.3)
|
25
|
+
http-cookie (~> 1.0)
|
26
|
+
http-form_data (~> 2.2)
|
27
|
+
http-parser (~> 1.2.0)
|
28
|
+
http-cookie (1.0.3)
|
29
|
+
domain_name (~> 0.5)
|
30
|
+
http-form_data (2.3.0)
|
31
|
+
http-parser (1.2.1)
|
32
|
+
ffi-compiler (>= 1.0, < 2.0)
|
33
|
+
public_suffix (4.0.1)
|
34
|
+
rake (10.5.0)
|
35
|
+
rspec (3.9.0)
|
36
|
+
rspec-core (~> 3.9.0)
|
37
|
+
rspec-expectations (~> 3.9.0)
|
38
|
+
rspec-mocks (~> 3.9.0)
|
39
|
+
rspec-core (3.9.0)
|
40
|
+
rspec-support (~> 3.9.0)
|
41
|
+
rspec-expectations (3.9.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.9.0)
|
44
|
+
rspec-mocks (3.9.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.9.0)
|
47
|
+
rspec-support (3.9.0)
|
48
|
+
safe_yaml (1.0.5)
|
49
|
+
unf (0.1.4)
|
50
|
+
unf_ext
|
51
|
+
unf_ext (0.0.7.7)
|
52
|
+
webmock (3.7.6)
|
53
|
+
addressable (>= 2.3.6)
|
54
|
+
crack (>= 0.3.2)
|
55
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
byebug
|
62
|
+
currency-rate!
|
63
|
+
rake (~> 10.0)
|
64
|
+
rspec (~> 3.0)
|
65
|
+
webmock
|
66
|
+
|
67
|
+
BUNDLED WITH
|
68
|
+
2.1.2
|
data/README.md
CHANGED
@@ -20,8 +20,8 @@ CurrencyRate.configure do |config|
|
|
20
20
|
# Empty array by default
|
21
21
|
config.api_keys["ForgeAdapter"] = "forge_api_key"
|
22
22
|
|
23
|
-
# CurrencyRate::FileStorage
|
24
|
-
config.
|
23
|
+
# CurrencyRate::FileStorage is built-in storage provider and has only `path` parameter
|
24
|
+
config.storage << CurrencyRate::FileStorage(path: "/home/user/data")
|
25
25
|
|
26
26
|
# CurrencyRate uses default Logger from Ruby core library
|
27
27
|
# It can be replaced with any compatible object
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
9
9
|
task :default => :spec
|
10
10
|
|
11
11
|
desc "Update rates for specified adapter"
|
12
|
-
task :update_rates, [:exchange] do |
|
12
|
+
task :update_rates, [:exchange] do |_, args|
|
13
13
|
api_keys = YAML.load_file("api_keys.yml")
|
14
14
|
|
15
15
|
CurrencyRate.configure do |config|
|
@@ -20,15 +20,24 @@ task :update_rates, [:exchange] do |t, args|
|
|
20
20
|
|
21
21
|
print "Loading data for #{args.exchange}... "
|
22
22
|
exchange_data = adapter.exchange_data
|
23
|
-
raw_storage = CurrencyRate::FileStorage.new(File.expand_path("spec/fixtures/adapters", __dir__))
|
23
|
+
raw_storage = CurrencyRate::FileStorage.new(path: File.expand_path("spec/fixtures/adapters", __dir__))
|
24
24
|
raw_storage.write(args.exchange, exchange_data)
|
25
25
|
puts "Success!"
|
26
26
|
|
27
27
|
print "Normalizing data for #{args.exchange}..."
|
28
28
|
normalized_data = adapter.normalize exchange_data
|
29
|
-
normalized_storage = CurrencyRate::FileStorage.new(File.expand_path("spec/fixtures/adapters/normalized", __dir__))
|
29
|
+
normalized_storage = CurrencyRate::FileStorage.new(path: File.expand_path("spec/fixtures/adapters/normalized", __dir__))
|
30
30
|
normalized_storage.write(args.exchange, normalized_data)
|
31
31
|
puts "Success!"
|
32
32
|
|
33
33
|
puts "#{args.exchange} fixtures update finished!"
|
34
34
|
end
|
35
|
+
|
36
|
+
desc "Update rates for all defined adapters"
|
37
|
+
task :update_all_rates do |_, _|
|
38
|
+
CurrencyRate.constants.grep(/.Adapter$/).each do |name|
|
39
|
+
short_name = name.to_s.sub("Adapter", "")
|
40
|
+
Rake::Task[:update_rates].invoke(short_name)
|
41
|
+
Rake::Task[:update_rates].reenable
|
42
|
+
end
|
43
|
+
end
|
data/currency-rate.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
|
-
spec.add_dependency "http", ">=
|
34
|
+
spec.add_dependency "http", ">= 4.3"
|
35
35
|
|
36
36
|
spec.add_development_dependency "byebug"
|
37
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/adapter.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module CurrencyRate
|
3
2
|
class Adapter
|
4
3
|
include Singleton
|
@@ -59,7 +58,13 @@ module CurrencyRate
|
|
59
58
|
fetch_url << "#{param_symbol}#{self.class::API_KEY_PARAM}=#{api_key}" if api_key
|
60
59
|
end
|
61
60
|
http_client = HTTP.timeout(connect: CurrencyRate.configuration.connect_timeout, read: CurrencyRate.configuration.read_timeout)
|
62
|
-
JSON.parse(
|
61
|
+
JSON.parse(
|
62
|
+
http_client
|
63
|
+
.headers("Accept" => "application/json; version=1")
|
64
|
+
.headers("Content-Type" => "text/plain")
|
65
|
+
.get(fetch_url)
|
66
|
+
.to_s
|
67
|
+
)
|
63
68
|
end
|
64
69
|
|
65
70
|
end
|
@@ -6,13 +6,14 @@ module CurrencyRate
|
|
6
6
|
DAD DAI DAT DGB DASH DTA DTH EDO ELF EOS ESS ETC ETH ETP EUR FSN FUN GBP
|
7
7
|
GNT HOT IOS IOT IQX JPY KNC LRC LTC LYM MIT MKR MNA MTN NCA NEO ODE OMG
|
8
8
|
OMNI ORS PAI POA POY QSH QTM RBT RCN RDN REP REQ RLC RRT SAN SEE SEN SNG
|
9
|
-
SNT SPK STJ TNB TRX USD UTK VEE VET WAX WPR XLM XMR XRP XTZ XVG YYW ZCN
|
9
|
+
SNT SPK STJ TNB TRX USD USDT UTK VEE VET WAX WPR XLM XMR XRP XTZ XVG YYW ZCN
|
10
10
|
ZEC ZIL ZRX
|
11
11
|
)
|
12
12
|
|
13
13
|
ASSET_MAP = {
|
14
14
|
"DSH" => "DASH",
|
15
15
|
"OMN" => "OMNI",
|
16
|
+
"UST" => "USDT",
|
16
17
|
}
|
17
18
|
|
18
19
|
ANCHOR_CURRENCY = "BTC"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module CurrencyRate
|
2
|
+
class HitBTCAdapter < Adapter
|
3
|
+
SUPPORTED_CURRENCIES = %w(ZRC EDG IHT AEON SOC HBAR ZRX OPT APPC DRGN PTOY
|
4
|
+
XDN OKB CHSB NCT GUSD GET FUN EXP EMRX REV GHOST
|
5
|
+
BMH SNC DTR ERD SCL HMQ ACT ETC QTUM MTX SBTC
|
6
|
+
KIND SMT BTB SWFTC 1ST UTT AXPR NMR EVX IOTA XPRM
|
7
|
+
STMX SALT DGB NTK AMM ALGO ORMEUS BDG BQX EKO FYP
|
8
|
+
IPX HOT MG BTS ADX CRPT WAXP POA PLBT SHIP HTML
|
9
|
+
BOX GNO UBT BTT ZEN VEO POA20 BCPT SRN XPR ETHBNT
|
10
|
+
MANA QKC MLN FLP SOLO TRUE VSYS JST GNT BOS PHB
|
11
|
+
ZEC ESH SWM NANO VIBE HVN SOLVE ELEC LRC AGI LNC
|
12
|
+
WAVES WTC ONT STRAT GNX NEU BCN XPNT ECA ARDR KIN
|
13
|
+
LSK USE IOTX CRO IDH LINK OAX CPT NGC XNS KEY TKY
|
14
|
+
HSR TNT SMART TRST DCR WINGS GT MKR ONE DOGE ARN
|
15
|
+
ACAT BMC RAISE EXM TIME REX FDZ HT MTH SCC BET
|
16
|
+
DENT IDRT IPL ZAP CMCT TDP XAUR MTL NEBL SUSDT BAT
|
17
|
+
STEEM CUR BYTZ PRO LOOM USD DRG DICE ADK COMP DRT
|
18
|
+
XTZ WETH EURS CHZ NEO NPLC XCON LEVL PAX AIM PART
|
19
|
+
PRE ERK HEDG FET PAXG DAG AVA CUTE NEXO DAY PITCH
|
20
|
+
MITX NXT POWR PLR CVCOIN TUSD MYST DLT REM RLC DNA
|
21
|
+
FOTA SBD ELF TEL C20 PNT CND UTK ASI CVC ETP ETH
|
22
|
+
ZIL ARPA INK NPXS LEO MESH NIM DATX FXT PBT GST
|
23
|
+
BSV GAS CBC MCO SENT GBX XRC POE SUR LOC WIKI PPT
|
24
|
+
CVT APM LEND NUT DOV KMD AYA LUN XEM RVN BCD XMR
|
25
|
+
NWC USG CLO NLC2 BBTC BERRY ART GRIN VITAE XBP OMG
|
26
|
+
MDA KRL BCH POLY PLA BANCA ENJ TRIGX UUU PASS ANT
|
27
|
+
LAMB BIZZ RFR AMB ROOBEE BST LCC RCN MIN BUSD DIT
|
28
|
+
PPC AE IQ BNK CENNZ SUB OCN DGD VRA STX AERGO HGT
|
29
|
+
TRAD IGNIS REP DAPP DNT CDT YCC SNGLS ICX PKT COV
|
30
|
+
PAY ABYSS BLZ DAV TKN ERT SPC SEELE XZC MAID AUTO
|
31
|
+
REN DATA AUC TV LAVA KAVA DAI DAPS ADA COCOS MITH
|
32
|
+
SETH NRG PHX DASH VLX CHAT VET EOSDT ZSC KNC DGTX
|
33
|
+
CEL SHORTUSD IOST BNB PBTT XMC EMC VIB BNT STORJ
|
34
|
+
ATOM LCX SC FTT BTM XLM TRX CELR BRD DBIX ETN SNT
|
35
|
+
MOF HEX XUC PLU FACE TNC SIG PXG BDP BTX TAU DCT
|
36
|
+
YOYOW SYBC SWT MAN GLEEC EOS XVG NAV CURE XRP KICK
|
37
|
+
BRDG LTC USDC MATIC FTX BTG PMA).freeze
|
38
|
+
|
39
|
+
ANCHOR_CURRENCY = "BTC".freeze
|
40
|
+
|
41
|
+
FETCH_URL = "https://api.hitbtc.com/api/2/public/ticker".freeze
|
42
|
+
|
43
|
+
def normalize(data)
|
44
|
+
return nil unless super
|
45
|
+
|
46
|
+
data.each_with_object({ "anchor" => ANCHOR_CURRENCY }) do |pair_info, result|
|
47
|
+
pair_name = pair_info["symbol"]
|
48
|
+
next unless pair_name.include?(ANCHOR_CURRENCY)
|
49
|
+
|
50
|
+
key = pair_name.sub(ANCHOR_CURRENCY, "")
|
51
|
+
|
52
|
+
result[key] =
|
53
|
+
if pair_name.index(ANCHOR_CURRENCY) == 0
|
54
|
+
BigDecimal(pair_info["last"])
|
55
|
+
else
|
56
|
+
1 / BigDecimal(pair_info["last"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -1,17 +1,25 @@
|
|
1
1
|
module CurrencyRate
|
2
2
|
class HuobiAdapter < Adapter
|
3
|
-
FETCH_URL =
|
4
|
-
|
5
|
-
|
6
|
-
}
|
3
|
+
FETCH_URL = "https://api.huobi.pro/market/tickers".freeze
|
4
|
+
|
5
|
+
ANCHOR_CURRENCY = "BTC"
|
7
6
|
|
8
7
|
def normalize(data)
|
9
8
|
return nil unless super
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
|
10
|
+
data["data"].each_with_object({ "anchor" => ANCHOR_CURRENCY }) do |pair_info, result|
|
11
|
+
pair_name = pair_info["symbol"].upcase
|
12
|
+
next unless pair_name.include?(ANCHOR_CURRENCY)
|
13
|
+
|
14
|
+
key = pair_name.sub(ANCHOR_CURRENCY, "")
|
15
|
+
|
16
|
+
result[key] =
|
17
|
+
if pair_name.index(ANCHOR_CURRENCY) == 0
|
18
|
+
BigDecimal(pair_info["close"].to_s)
|
19
|
+
else
|
20
|
+
1 / BigDecimal(pair_info["close"].to_s)
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
15
|
-
|
16
24
|
end
|
17
25
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module CurrencyRate
|
2
2
|
class KrakenAdapter < Adapter
|
3
3
|
SUPPORTED_CURRENCIES = %w(
|
4
|
-
ADA BCH BSV BTC DASH EOS ETC ETH GNO LTC MLN
|
5
|
-
NMC QTUM REP XDG XLM XMR XRP XTZ ZEC
|
4
|
+
ADA BCH BSV BTC DAI DASH EOS ETC ETH GNO LTC MLN
|
5
|
+
NMC QTUM REP USDC XDG XLM XMR XRP XTZ ZEC
|
6
6
|
)
|
7
7
|
|
8
8
|
ASSET_MAP = {
|
@@ -21,14 +21,14 @@ module CurrencyRate
|
|
21
21
|
|
22
22
|
ANCHOR_CURRENCY = "BTC"
|
23
23
|
|
24
|
-
FETCH_URL = "https://api.kraken.com/0/public/Ticker?pair=#{ %w(ADAXBT BCHXBT BSVXBT DASHXBT EOSXBT GNOXBT QTUMXBT XTZXBT XETCXXBT XETHXXBT XLTCXXBT XREPXXBT XXLMXXBT XXMRXXBT XXRPXXBT XZECXXBT XXBTZUSD).join(",") }"
|
24
|
+
FETCH_URL = "https://api.kraken.com/0/public/Ticker?pair=#{ %w(ADAXBT BCHXBT BSVXBT DASHXBT EOSXBT GNOXBT QTUMXBT XTZXBT XETCXXBT XETHXXBT XLTCXXBT XREPXXBT XXLMXXBT XXMRXXBT XXRPXXBT XZECXXBT XXBTZUSD XBTDAI XBTUSDC).join(",") }"
|
25
25
|
|
26
26
|
def normalize(data)
|
27
27
|
return nil unless super
|
28
28
|
data["result"].reduce({ "anchor" => ANCHOR_CURRENCY }) do |result, (pair, value)|
|
29
29
|
key = ta(pair.sub(ta(ANCHOR_CURRENCY), ""))
|
30
30
|
|
31
|
-
if
|
31
|
+
if %w(USD DAI USDC).include?(key)
|
32
32
|
result[key] = BigDecimal(value["c"].first.to_s)
|
33
33
|
else
|
34
34
|
result[key] = 1 / BigDecimal(value["c"].first.to_s)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CurrencyRate
|
2
|
+
class PaxfulAdapter < Adapter
|
3
|
+
SUPPORTED_CURRENCIES = %w(USD)
|
4
|
+
|
5
|
+
ANCHOR_CURRENCY = "BTC"
|
6
|
+
|
7
|
+
FETCH_URL = "https://paxful.com/api/currency/btc"
|
8
|
+
|
9
|
+
def normalize(data)
|
10
|
+
return nil unless super
|
11
|
+
|
12
|
+
{
|
13
|
+
"anchor" => ANCHOR_CURRENCY,
|
14
|
+
"USD" => BigDecimal(data["price"].to_s)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module CurrencyRate
|
2
|
+
class PoloniexAdapter < Adapter
|
3
|
+
SUPPORTED_CURRENCIES = %w(BTS DASH DOGE LTC NXT STR XEM XMR XRP USDT
|
4
|
+
ETH SC DCR LSK STEEM ETC REP ARDR ZEC STRAT
|
5
|
+
GNT ZRX CVC OMG GAS STORJ EOS SNT KNC BAT
|
6
|
+
LOOM QTUM USDC MANA BNT BCHABC BCHSV FOAM
|
7
|
+
NMR POLY LPT ATOM TRX ETHBNT LINK XTZ PAX
|
8
|
+
USDJ SNX MATIC MKR DAI NEO SWFTC FXC AVA
|
9
|
+
CHR BNB BUSD MDT XFIL LEND REN LRC WRX SXP
|
10
|
+
STPT SWAP EXE).freeze
|
11
|
+
|
12
|
+
ANCHOR_CURRENCY = "BTC".freeze
|
13
|
+
|
14
|
+
FETCH_URL = "https://poloniex.com/public?command=returnTicker".freeze
|
15
|
+
|
16
|
+
def normalize(data)
|
17
|
+
return nil unless super
|
18
|
+
|
19
|
+
data.each_with_object({ "anchor" => ANCHOR_CURRENCY }) do |(pair_name, pair_info), result|
|
20
|
+
next unless pair_name.include?(ANCHOR_CURRENCY)
|
21
|
+
|
22
|
+
key = pair_name.sub(ANCHOR_CURRENCY, "").sub("_", "")
|
23
|
+
|
24
|
+
result[key] =
|
25
|
+
if pair_name.index(ANCHOR_CURRENCY) == 0
|
26
|
+
1 / BigDecimal(pair_info["last"])
|
27
|
+
else
|
28
|
+
BigDecimal(pair_info["last"])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CurrencyRate
|
2
|
+
class YadioAdapter < Adapter
|
3
|
+
SUPPORTED_CURRENCIES = %w(VES)
|
4
|
+
|
5
|
+
ANCHOR_CURRENCY = "BTC"
|
6
|
+
|
7
|
+
FETCH_URL = "https://api.yadio.io/rate/BTC"
|
8
|
+
|
9
|
+
def normalize(data)
|
10
|
+
return nil unless super
|
11
|
+
|
12
|
+
{
|
13
|
+
"anchor" => ANCHOR_CURRENCY,
|
14
|
+
"USD" => BigDecimal(data["usd"].to_s),
|
15
|
+
"VES" => BigDecimal(data["rate"].to_s),
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/configuration.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module CurrencyRate
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_keys
|
4
|
-
attr_accessor :file_storage
|
5
4
|
attr_accessor :logger
|
6
5
|
attr_accessor :crypto_adapters
|
7
6
|
attr_accessor :fiat_adapters
|
8
7
|
attr_accessor :connect_timeout
|
9
8
|
attr_accessor :read_timeout
|
9
|
+
attr_accessor :storage
|
10
10
|
attr_accessor :limit_sources_for_fiat_currencies
|
11
11
|
attr_accessor :crypto_currencies
|
12
12
|
|
13
13
|
def initialize
|
14
14
|
@api_keys = { }
|
15
|
-
@file_storage = { path: "" }
|
16
15
|
@logger = {
|
17
16
|
device: $stdout,
|
18
17
|
level: :info,
|
data/lib/currency_rate.rb
CHANGED
data/lib/exceptions.rb
ADDED
data/lib/fetcher.rb
CHANGED
@@ -6,7 +6,9 @@ module CurrencyRate
|
|
6
6
|
attr_accessor :limit_sources_for_fiat_currencies
|
7
7
|
|
8
8
|
def initialize(fiat_exchanges: nil, crypto_exchanges: nil, storage: nil, limit_sources_for_fiat_currencies: {})
|
9
|
-
@storage = storage ||
|
9
|
+
@storage = storage || CurrencyRate.configuration.storage
|
10
|
+
raise CurrencyRate::StorageNotDefinedError unless @storage
|
11
|
+
|
10
12
|
@fiat_exchanges = fiat_exchanges || ["Yahoo", "Fixer", "Forge"]
|
11
13
|
@crypto_exchanges = crypto_exchanges || ["Bitstamp", "Binance"]
|
12
14
|
@limit_sources_for_fiat_currencies = limit_sources_for_fiat_currencies
|
data/lib/storage/file_storage.rb
CHANGED
@@ -3,8 +3,8 @@ module CurrencyRate
|
|
3
3
|
attr_reader :path
|
4
4
|
attr_accessor :serializer
|
5
5
|
|
6
|
-
def initialize(path
|
7
|
-
@path = path
|
6
|
+
def initialize(path:, serializer: nil)
|
7
|
+
@path = path
|
8
8
|
@serializer = serializer || Storage::YAMLSerializer.new
|
9
9
|
end
|
10
10
|
|
data/lib/synchronizer.rb
CHANGED
@@ -3,7 +3,8 @@ module CurrencyRate
|
|
3
3
|
attr_accessor :storage
|
4
4
|
|
5
5
|
def initialize(storage: nil)
|
6
|
-
@storage = storage ||
|
6
|
+
@storage = storage || CurrencyRate.configuration.storage
|
7
|
+
raise CurrencyRate::StorageNotDefinedError unless @storage
|
7
8
|
end
|
8
9
|
|
9
10
|
def sync_fiat!
|
@@ -28,14 +29,16 @@ module CurrencyRate
|
|
28
29
|
adapters.each do |provider|
|
29
30
|
adapter_name = "#{provider}Adapter"
|
30
31
|
begin
|
31
|
-
adapter = CurrencyRate
|
32
|
+
adapter = CurrencyRate.const_get(adapter_name).instance
|
32
33
|
rates = adapter.fetch_rates
|
34
|
+
|
33
35
|
unless rates
|
34
36
|
CurrencyRate.logger.warn("Synchronizer#sync!: rates for #{provider} not found")
|
35
37
|
failed.push(provider)
|
36
38
|
next
|
37
39
|
end
|
38
|
-
|
40
|
+
|
41
|
+
exchange_name = provider
|
39
42
|
@storage.write(exchange_name, rates)
|
40
43
|
successfull.push(provider)
|
41
44
|
rescue StandardError => e
|
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: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Snitko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,12 +90,11 @@ files:
|
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
92
|
- Gemfile
|
93
|
+
- Gemfile.lock
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- api_keys.yml.sample
|
97
|
-
- bin/rake
|
98
|
-
- bin/rspec
|
99
98
|
- currency-rate.gemspec
|
100
99
|
- lib/adapter.rb
|
101
100
|
- lib/adapters/crypto/binance_adapter.rb
|
@@ -107,10 +106,14 @@ files:
|
|
107
106
|
- lib/adapters/crypto/coin_market_cap_adapter.rb
|
108
107
|
- lib/adapters/crypto/coinbase_adapter.rb
|
109
108
|
- lib/adapters/crypto/exmo_adapter.rb
|
109
|
+
- lib/adapters/crypto/hit_btc_adapter.rb
|
110
110
|
- lib/adapters/crypto/huobi_adapter.rb
|
111
111
|
- lib/adapters/crypto/kraken_adapter.rb
|
112
112
|
- lib/adapters/crypto/localbitcoins_adapter.rb
|
113
113
|
- lib/adapters/crypto/okcoin_adapter.rb
|
114
|
+
- lib/adapters/crypto/paxful_adapter.rb
|
115
|
+
- lib/adapters/crypto/poloniex_adapter.rb
|
116
|
+
- lib/adapters/crypto/yadio_adapter.rb
|
114
117
|
- lib/adapters/fiat/bonbast_adapter.rb
|
115
118
|
- lib/adapters/fiat/coinmonitor_adapter.rb
|
116
119
|
- lib/adapters/fiat/currency_layer_adapter.rb
|
@@ -121,6 +124,7 @@ files:
|
|
121
124
|
- lib/configuration.rb
|
122
125
|
- lib/currency_rate.rb
|
123
126
|
- lib/currency_rate/version.rb
|
127
|
+
- lib/exceptions.rb
|
124
128
|
- lib/fetcher.rb
|
125
129
|
- lib/storage/file_storage.rb
|
126
130
|
- lib/storage/serializers/yaml_serializer.rb
|
@@ -146,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
150
|
- !ruby/object:Gem::Version
|
147
151
|
version: '0'
|
148
152
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.1.4
|
150
154
|
signing_key:
|
151
155
|
specification_version: 4
|
152
156
|
summary: Converter for fiat and crypto currencies
|
data/bin/rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rake' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
#
|
5
|
-
# This file was generated by Bundler.
|
6
|
-
#
|
7
|
-
# The application 'rspec' is installed as part of a gem, and
|
8
|
-
# this file is here to facilitate running it.
|
9
|
-
#
|
10
|
-
|
11
|
-
require "pathname"
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
-
Pathname.new(__FILE__).realpath)
|
14
|
-
|
15
|
-
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
-
|
17
|
-
if File.file?(bundle_binstub)
|
18
|
-
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
-
load(bundle_binstub)
|
20
|
-
else
|
21
|
-
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
-
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require "rubygems"
|
27
|
-
require "bundler/setup"
|
28
|
-
|
29
|
-
load Gem.bin_path("rspec-core", "rspec")
|