class Bitcoin::Trade

Attributes

id[RW]
price[RW]
quantity[RW]
side[RW]
symbol[RW]
timestamp[RW]

Public Class Methods

all(symbol_name) click to toggle source
# File lib/bitcoin/trade.rb, line 26
def self.all(symbol_name)
  data = JSON.parse RestClient.get("#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000")
  data.map{ |e|
    Bitcoin::Trade.new_from_object(symbol_name, e)
  }
end
get_trades_in_range(symbol_name, timestamps = nil) click to toggle source

Input: currency pair and formatted date range. Output: array of trades from range

# File lib/bitcoin/trade.rb, line 34
def self.get_trades_in_range(symbol_name, timestamps = nil)
  data = JSON.parse RestClient.get "#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000&sort=DESC&from=#{timestamps[0]}&till=#{timestamps[1]}"
  data.map{|e|
    Bitcoin::Trade.new_from_object(symbol_name, e)
  }
end
new_from_object(symbol_name, data) click to toggle source
# File lib/bitcoin/trade.rb, line 15
def self.new_from_object(symbol_name, data)
  t = Bitcoin::Trade.new
  t.id = data['id']
  t.price = data['price'].to_f
  t.quantity = data['quantity'].to_f
  t.side = data['side']
  t.timestamp = Time.parse(data['timestamp'])
  t.symbol = symbol_name
  t
end

Public Instance Methods

display_details() click to toggle source
# File lib/bitcoin/trade.rb, line 5
  def display_details
    puts <<-DOC
  | #{@symbol}
  | ID: #{@id} : #{@side.upcase} : #{@price}
  | Quantity: #{@quantity}
  | #{@timestamp}
  |_____________________
    DOC
  end