Sha256: de7d09d78b0f5f8efd966384327e633b9fe72cb80d30d5d2ace9ce19371cde5c

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Mcoin
  module Command
    # :nodoc:
    class Ticker < Base
      include HasMarket
      include HasPair
      include Saveable

      attr_reader :option

      description 'Show market information'

      def execute
        raise OptionParser::MissingArgument, :market if option.market.nil?
        print
        save if save?
      end

      def print
        tickers = Parallel.map(markets, :fetch).compact.map(&:to_ticker).flatten
        Printer.new(tickers).print
      end

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

      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

      def pairs
        @pairs ||= (option.pair || ['BTC-USD']).uniq.map do |pair|
          pair.split('-').map(&:to_sym)
        end
      end

      private

      def prepare
        super
        option.pair ||= []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mcoin-0.6.0 lib/mcoin/command/ticker.rb