Sha256: 5d5d3b6c6cfe1a479ece7662a7e359980fc576753dbc66fb784e22aa3b21f4cc

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class Bitcoin::Display

  def self.list(array)
    numerize(array)
  end

  def self.list_by_symbol(array)
    numerize(array, :symbol)
  end

  def self.list_by_id(array)
    numerize(array, :id)
  end

  def self.list_trades(trades)
    trades.each_with_index{ |trade, i|
      puts "#{(i+1).to_s.rjust(4)}. #{trade.timestamp.strftime("%Y-%m-%d %H:%M:%S")} #{trade.side.rjust(4)} #{trade.price}"
    }
  end

  def self.list_order_book(orderbook)
    orderbook.each_with_index{ |order, i|
      puts "#{(i+1).to_s.rjust(4)}. #{order.timestamp.strftime("%Y-%m-%d %H:%M:%S")}:  #{order.side.upcase} - Order Size: #{order.size.to_s.rjust(12)}, Price: #{order.price.to_s.rjust(12)}"
    }
  end

  def self.list_candles(candles)
    candles.each_with_index{ |candle, i|
      puts "#{(i+1).to_s.rjust(4)}. #{candle.timestamp} [#{candle.open.rjust(11)} -> #{candle.close.rjust(11)}] [#{candle.min.rjust(11)} - #{candle.max.rjust(11)}] vol: #{candle.volume.rjust(11)}"
    }
    # insert key at top and bottom of list
  end

  def self.list_tickers(tickers)
    tickers.each_with_index{ |ticker, i|
      puts "#{(i+1).to_s.rjust(4)}. #{ticker.symbol}"
    }
  end

  private
  # input array of hashes, and attribute to be displayed
  def self.numerize(array, attribute = nil)
    if attribute
      array.each_with_index{ |e, i| puts "#{i+1}. #{e.send("#{attribute}")}"}
    else
      array.each_with_index{ |e, i| puts "#{i+1}. #{e}"}
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitcoin-api-0.1.1 lib/bitcoin/display.rb