Class: Bitcoin::OrderBook

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/order_book.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



3
4
5
# File 'lib/bitcoin/order_book.rb', line 3

def limit
  @limit
end

#priceObject

Returns the value of attribute price.



3
4
5
# File 'lib/bitcoin/order_book.rb', line 3

def price
  @price
end

#sideObject

Returns the value of attribute side.



3
4
5
# File 'lib/bitcoin/order_book.rb', line 3

def side
  @side
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/bitcoin/order_book.rb', line 3

def size
  @size
end

#symbolObject

Returns the value of attribute symbol.



3
4
5
# File 'lib/bitcoin/order_book.rb', line 3

def symbol
  @symbol
end

#timestampObject

Returns the value of attribute timestamp.



3
4
5
# File 'lib/bitcoin/order_book.rb', line 3

def timestamp
  @timestamp
end

Class Method Details

.all(symbol_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bitcoin/order_book.rb', line 26

def self.all(symbol_name)
  data = JSON.parse RestClient.get "#{Bitcoin::BASE}/public/orderbook/#{symbol_name}?limit=0"
  ask_orders = data['ask']
  bid_orders = data['bid']

  ask_orders.each{ |order|
    order[:side] = 'ask'
    order['timestamp'] = data['timestamp']
    order[:symbol] = symbol_name
  }
  bid_orders.each{ |order|
    order[:side] = 'bid'
    order['timestamp'] = data['timestamp']
    order[:symbol] = symbol_name
  }

  [ask_orders, bid_orders].flatten!.map{|order|
    Bitcoin::OrderBook.new_from_object(order)
  }
end

.new_from_object(object) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/bitcoin/order_book.rb', line 15

def self.new_from_object(object)
  o = Bitcoin::OrderBook.new
  o.size = object['size'].to_f
  o.side = object[:side]
  o.price = object['price'].to_f
  o.timestamp = Time.parse(object['timestamp'])
  o.limit = object['limit']
  o.symbol = object[:symbol]
  o
end

Instance Method Details

#display_detailsObject



5
6
7
8
9
10
11
12
13
# File 'lib/bitcoin/order_book.rb', line 5

def display_details
  puts <<-DOC
  #{@symbol} #{@side.upcase} Order:
  #{@price}
  Quantity: #{@size}
  #{@timestamp}

  DOC
end