Class: Mcoin::Command::Ticker
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Saveable
#database, included, #save?
Methods included from HasPair
included
Methods included from HasMarket
included
Methods inherited from Base
description, #initialize, option, #parse!
Instance Attribute Details
#option ⇒ Object
Returns the value of attribute option.
11
12
13
|
# File 'lib/mcoin/command/ticker.rb', line 11
def option
@option
end
|
Instance Method Details
#execute ⇒ Object
15
16
17
18
19
|
# File 'lib/mcoin/command/ticker.rb', line 15
def execute
raise OptionParser::MissingArgument, :market if option.market.nil?
print
save if save?
end
|
#markets ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/mcoin/command/ticker.rb', line 30
def markets
@markets ||= option.market.map do |name|
market = Market.pick(name).new
pairs.map do |pair|
market.watch(*pair)
end
market
end.flatten
end
|
#pairs ⇒ Object
40
41
42
43
44
|
# File 'lib/mcoin/command/ticker.rb', line 40
def pairs
@pairs ||= (option.pair || ['BTC-USD']).uniq.map do |pair|
pair.split('-').map(&:to_sym)
end
end
|
#print ⇒ Object
21
22
23
24
|
# File 'lib/mcoin/command/ticker.rb', line 21
def print
tickers = Parallel.map(markets, :fetch).compact.map(&:to_ticker).flatten
Printer.new(tickers).print
end
|
#save ⇒ Object
26
27
28
|
# File 'lib/mcoin/command/ticker.rb', line 26
def save
database.save(markets.map(&:to_ticker).flatten.map(&:to_influx))
end
|