lib/mcoin/subscriber.rb in mcoin-0.4.0 vs lib/mcoin/subscriber.rb in mcoin-0.5.0
- old
+ new
@@ -1,13 +1,14 @@
# frozen_string_literal: true
module Mcoin
class Subscriber
- attr_reader :markets
+ attr_reader :markets, :pairs
- def initialize(picked = Market.available, type = :BTC, currency = :USD)
- @markets = markets_from(picked, type, currency)
+ def initialize(pairs = [], market = Market.available)
+ @pairs = pairs_from(pairs)
+ @markets = markets_from(market)
end
def start(interval = 1, &block)
loop do
Parallel.async(markets, :fetch) do |result|
@@ -17,14 +18,22 @@
end
end
protected
- def markets_from(picked, type, currency)
- @markets ||= picked.map do |name|
- Market
- .pick(name)
- .new(type, currency)
+ def pairs_from(picked)
+ @pairs ||= (picked || ['BTC-USD']).uniq.map do |pair|
+ pair.split('-').map(&:to_sym)
end
+ end
+
+ def markets_from(picked)
+ @markets ||= picked.map do |name|
+ pairs.map do |pair|
+ Market
+ .pick(name)
+ .new(*pair)
+ end
+ end.flatten
end
end
end