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
9 10 11 |
# File 'lib/cryptoexchange/client.rb', line 9 def initialize(ticker_ttl: 3) LruTtlCache.ticker_cache(ticker_ttl) end |
Class Method Details
.available_exchanges ⇒ Object
4 5 6 |
# File 'lib/cryptoexchange/client.rb', line 4 def available_exchanges Dir.entries("./lib/cryptoexchange/exchanges")[2..-1] end |
Instance Method Details
#pairs(exchange) ⇒ Object
13 14 15 16 |
# File 'lib/cryptoexchange/client.rb', line 13 def pairs(exchange) pairs_classname = "Cryptoexchange::Exchanges::#{StringHelper.camelize(exchange)}::Services::Pairs" Object.const_get(pairs_classname).new.fetch end |
#ticker(market_pair) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cryptoexchange/client.rb', line 18 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 |