Class: Cryptoexchange::Client
- Inherits:
-
Object
- Object
- Cryptoexchange::Client
- Defined in:
- lib/cryptoexchange/client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ticker_ttl: 3) ⇒ Client
constructor
A new instance of Client.
- #pairs(exchange) ⇒ Object
- #ticker(market_pair) ⇒ Object
Constructor Details
#initialize(ticker_ttl: 3) ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'lib/cryptoexchange/client.rb', line 11 def initialize(ticker_ttl: 3) LruTtlCache.ticker_cache(ticker_ttl) end |
Class Method Details
.available_exchanges ⇒ Object
4 5 6 7 8 |
# File 'lib/cryptoexchange/client.rb', line 4 def available_exchanges root_dir = File.dirname __dir__ exchanges_dir = File.join(root_dir, 'cryptoexchange', 'exchanges') Dir.entries(exchanges_dir)[2..-1] end |
Instance Method Details
#pairs(exchange) ⇒ Object
15 16 17 18 |
# File 'lib/cryptoexchange/client.rb', line 15 def pairs(exchange) pairs_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Pairs" Object.const_get(pairs_classname).new.fetch end |
#ticker(market_pair) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cryptoexchange/client.rb', line 20 def ticker(market_pair) exchange = market_pair.market market_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Market" market_class = Object.const_get(market_classname) market = market_class.new if market_class.supports_individual_ticker_query? market.fetch(market_pair) else tickers = market.fetch tickers.find do |t| t.base == market_pair.base && t.target == market_pair.target end end end |