Class: Mcoin::Command::Ticker

Inherits:
Base
  • Object
show all
Includes:
HasMarket, HasPair, Saveable
Defined in:
lib/mcoin/command/ticker.rb

Overview

:nodoc:

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!

Constructor Details

This class inherits a constructor from Mcoin::Command::Base

Instance Attribute Details

#optionObject (readonly)

Returns the value of attribute option.



11
12
13
# File 'lib/mcoin/command/ticker.rb', line 11

def option
  @option
end

Instance Method Details

#executeObject

Raises:

  • (OptionParser::MissingArgument)


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

#marketsObject



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

#pairsObject



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


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

#saveObject



26
27
28
# File 'lib/mcoin/command/ticker.rb', line 26

def save
  database.save(markets.map(&:to_ticker).flatten.map(&:to_influx))
end