Class: Bitcoin::OrderBook
- Inherits:
-
Object
- Object
- Bitcoin::OrderBook
- Defined in:
- lib/bitcoin/order_book.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#price ⇒ Object
Returns the value of attribute price.
-
#side ⇒ Object
Returns the value of attribute side.
-
#size ⇒ Object
Returns the value of attribute size.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
3 4 5 |
# File 'lib/bitcoin/order_book.rb', line 3 def limit @limit end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/bitcoin/order_book.rb', line 3 def price @price end |
#side ⇒ Object
Returns the value of attribute side.
3 4 5 |
# File 'lib/bitcoin/order_book.rb', line 3 def side @side end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/bitcoin/order_book.rb', line 3 def size @size end |
#symbol ⇒ Object
Returns the value of attribute symbol.
3 4 5 |
# File 'lib/bitcoin/order_book.rb', line 3 def symbol @symbol end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/bitcoin/order_book.rb', line 3 def @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. = Time.parse(object['timestamp']) o.limit = object['limit'] o.symbol = object[:symbol] o end |
Instance Method Details
#display_details ⇒ Object
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 |