currency-rate 1.7.0 → 2.0.6

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. metadata +9 -125
  3. data/.document +0 -5
  4. data/.gitignore +0 -20
  5. data/.rspec +0 -1
  6. data/Gemfile +0 -6
  7. data/Gemfile.lock +0 -68
  8. data/LICENSE.txt +0 -20
  9. data/README.md +0 -73
  10. data/Rakefile +0 -43
  11. data/api_keys.yml.sample +0 -4
  12. data/currency-rate.gemspec +0 -41
  13. data/lib/adapter.rb +0 -71
  14. data/lib/adapters/crypto/binance_adapter.rb +0 -42
  15. data/lib/adapters/crypto/bitfinex_adapter.rb +0 -41
  16. data/lib/adapters/crypto/bitpay_adapter.rb +0 -29
  17. data/lib/adapters/crypto/bitstamp_adapter.rb +0 -26
  18. data/lib/adapters/crypto/btc_china_adapter.rb +0 -11
  19. data/lib/adapters/crypto/btc_e_adapter.rb +0 -18
  20. data/lib/adapters/crypto/coin_market_cap_adapter.rb +0 -31
  21. data/lib/adapters/crypto/coinbase_adapter.rb +0 -30
  22. data/lib/adapters/crypto/exmo_adapter.rb +0 -27
  23. data/lib/adapters/crypto/hit_btc_adapter.rb +0 -61
  24. data/lib/adapters/crypto/huobi_adapter.rb +0 -25
  25. data/lib/adapters/crypto/kraken_adapter.rb +0 -46
  26. data/lib/adapters/crypto/localbitcoins_adapter.rb +0 -25
  27. data/lib/adapters/crypto/okcoin_adapter.rb +0 -19
  28. data/lib/adapters/crypto/paxful_adapter.rb +0 -18
  29. data/lib/adapters/crypto/poloniex_adapter.rb +0 -33
  30. data/lib/adapters/crypto/yadio_adapter.rb +0 -19
  31. data/lib/adapters/fiat/bonbast_adapter.rb +0 -25
  32. data/lib/adapters/fiat/coinmonitor_adapter.rb +0 -14
  33. data/lib/adapters/fiat/currency_layer_adapter.rb +0 -32
  34. data/lib/adapters/fiat/fixer_adapter.rb +0 -18
  35. data/lib/adapters/fiat/forge_adapter.rb +0 -25
  36. data/lib/adapters/fiat/free_forex_adapter.rb +0 -32
  37. data/lib/adapters/fiat/yahoo_adapter.rb +0 -35
  38. data/lib/configuration.rb +0 -28
  39. data/lib/currency_rate.rb +0 -85
  40. data/lib/currency_rate/version.rb +0 -3
  41. data/lib/exceptions.rb +0 -9
  42. data/lib/fetcher.rb +0 -80
  43. data/lib/storage/file_storage.rb +0 -29
  44. data/lib/storage/serializers/yaml_serializer.rb +0 -15
  45. data/lib/synchronizer.rb +0 -54
data/lib/fetcher.rb DELETED
@@ -1,80 +0,0 @@
1
- module CurrencyRate
2
- class Fetcher
3
- attr_accessor :storage
4
- attr_accessor :fiat_exchanges
5
- attr_accessor :crypto_exchanges
6
- attr_accessor :limit_sources_for_fiat_currencies
7
-
8
- def initialize(fiat_exchanges: nil, crypto_exchanges: nil, storage: nil, limit_sources_for_fiat_currencies: {})
9
- @storage = storage || CurrencyRate.configuration.storage
10
- raise CurrencyRate::StorageNotDefinedError unless @storage
11
-
12
- @fiat_exchanges = fiat_exchanges || ["Yahoo", "Fixer", "Forge"]
13
- @crypto_exchanges = crypto_exchanges || ["Bitstamp", "Binance"]
14
- @limit_sources_for_fiat_currencies = limit_sources_for_fiat_currencies
15
- end
16
-
17
- def fetch_crypto(exchange, from, to)
18
- from = from.strip.upcase
19
- to = to.strip.upcase
20
- rates = @storage.read(exchange)
21
-
22
- if rates.nil?
23
- CurrencyRate.logger.warn("Fetcher#fetch_crypto: rates for #{exchange} not found in storage <#{@storage.class.name}>")
24
- return nil
25
- end
26
-
27
- rate = calculate_rate(rates, from, to)
28
- return rate unless rate.nil?
29
-
30
- if to != "USD"
31
- usd_fiat = fetch_fiat("USD", to)
32
- return BigDecimal(rates["USD"] * usd_fiat) if usd_fiat && rates["USD"]
33
- end
34
- nil
35
- end
36
-
37
- def fetch_fiat(from, to)
38
- from = from.strip.upcase
39
- to = to.strip.upcase
40
-
41
- exchanges = @fiat_exchanges.dup
42
- exchanges += @crypto_exchanges if is_crypto_currency?(from) || is_crypto_currency?(to)
43
-
44
- if(@limit_sources_for_fiat_currencies[from])
45
- exchanges.select! { |ex| @limit_sources_for_fiat_currencies[from].include?(ex) }
46
- end
47
- if(@limit_sources_for_fiat_currencies[to])
48
- exchanges.select! { |ex| @limit_sources_for_fiat_currencies[to].include?(ex) }
49
- end
50
-
51
- exchanges.each do |exchange|
52
- rates = @storage.read(exchange)
53
- next if rates.nil?
54
-
55
- rate = calculate_rate(rates, from, to)
56
- return rate unless rate.nil?
57
- end
58
- nil
59
- end
60
-
61
- private
62
-
63
- def calculate_rate(rates, from, to)
64
- anchor = rates.delete("anchor")
65
-
66
- return BigDecimal(rates[to]) if anchor == from && rates[to]
67
- return BigDecimal(1 / rates[from]) if anchor == to && rates[from]
68
- return BigDecimal(rates[to] / rates[from]) if rates[from] && rates[to]
69
-
70
- CurrencyRate.logger.warn("Fetcher: rate for #{from}_#{to} not found.")
71
- nil
72
- end
73
-
74
- def is_crypto_currency?(currency)
75
- CurrencyRate.configuration.crypto_currencies.include?(currency)
76
- end
77
-
78
- end
79
- end
80
-
@@ -1,29 +0,0 @@
1
- module CurrencyRate
2
- class FileStorage
3
- attr_reader :path
4
- attr_accessor :serializer
5
-
6
- def initialize(path:, serializer: nil)
7
- @path = path
8
- @serializer = serializer || Storage::YAMLSerializer.new
9
- end
10
-
11
- def read(exchange_name)
12
- path = path_for exchange_name.downcase
13
- @serializer.deserialize File.read(path)
14
- rescue StandardError => e
15
- CurrencyRate.logger.error(e)
16
- nil
17
- end
18
-
19
- def write(exchange_name, data = "")
20
- File.write path_for(exchange_name.downcase), @serializer.serialize(data)
21
- rescue StandardError => e
22
- CurrencyRate.logger.error(e)
23
- end
24
-
25
- def path_for(exchange_name)
26
- File.join @path, "#{exchange_name}_rates.yml"
27
- end
28
- end
29
- end
@@ -1,15 +0,0 @@
1
- require "yaml"
2
-
3
- module CurrencyRate
4
- module Storage
5
- class YAMLSerializer
6
- def serialize(data)
7
- YAML.dump(data)
8
- end
9
-
10
- def deserialize(data)
11
- YAML.load(data)
12
- end
13
- end
14
- end
15
- end
data/lib/synchronizer.rb DELETED
@@ -1,54 +0,0 @@
1
- module CurrencyRate
2
- class Synchronizer
3
- attr_accessor :storage
4
-
5
- def initialize(storage: nil)
6
- @storage = storage || CurrencyRate.configuration.storage
7
- raise CurrencyRate::StorageNotDefinedError unless @storage
8
- end
9
-
10
- def sync_fiat!
11
- _sync CurrencyRate.configuration.fiat_adapters
12
- end
13
-
14
- def sync_crypto!
15
- _sync CurrencyRate.configuration.crypto_adapters
16
- end
17
-
18
- def sync!
19
- fiat = sync_fiat!
20
- crypto = sync_crypto!
21
- [fiat[0] | crypto[0], fiat[1] | crypto[1]]
22
- end
23
-
24
- private
25
-
26
- def _sync(adapters)
27
- successfull = []
28
- failed = []
29
- adapters.each do |provider|
30
- adapter_name = "#{provider}Adapter"
31
- begin
32
- adapter = CurrencyRate.const_get(adapter_name).instance
33
- rates = adapter.fetch_rates
34
-
35
- unless rates
36
- CurrencyRate.logger.warn("Synchronizer#sync!: rates for #{provider} not found")
37
- failed.push(provider)
38
- next
39
- end
40
-
41
- exchange_name = provider
42
- @storage.write(exchange_name, rates)
43
- successfull.push(provider)
44
- rescue StandardError => e
45
- failed.push({ provider: e })
46
- CurrencyRate.logger.error(e)
47
- next
48
- end
49
- end
50
- [successfull, failed]
51
- end
52
-
53
- end
54
- end