Class: Bitcoin::Trade
- Inherits:
-
Object
- Object
- Bitcoin::Trade
- Defined in:
- lib/bitcoin/trade.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#side ⇒ Object
Returns the value of attribute side.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
- .all(symbol_name) ⇒ Object
-
.get_trades_in_range(symbol_name, timestamps = nil) ⇒ Object
Input: currency pair and formatted date range.
- .new_from_object(symbol_name, data) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
permalink #id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/bitcoin/trade.rb', line 3 def id @id end |
permalink #price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/bitcoin/trade.rb', line 3 def price @price end |
permalink #quantity ⇒ Object
Returns the value of attribute quantity.
3 4 5 |
# File 'lib/bitcoin/trade.rb', line 3 def quantity @quantity end |
permalink #side ⇒ Object
Returns the value of attribute side.
3 4 5 |
# File 'lib/bitcoin/trade.rb', line 3 def side @side end |
permalink #symbol ⇒ Object
Returns the value of attribute symbol.
3 4 5 |
# File 'lib/bitcoin/trade.rb', line 3 def symbol @symbol end |
permalink #timestamp ⇒ Object
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/bitcoin/trade.rb', line 3 def @timestamp end |
Class Method Details
permalink .all(symbol_name) ⇒ Object
[View source]
26 27 28 29 30 31 |
# 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 |
permalink .get_trades_in_range(symbol_name, timestamps = nil) ⇒ Object
Input: currency pair and formatted date range. Output: array of trades from range
34 35 36 37 38 39 |
# File 'lib/bitcoin/trade.rb', line 34 def self.get_trades_in_range(symbol_name, = nil) data = JSON.parse RestClient.get "#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000&sort=DESC&from=#{[0]}&till=#{[1]}" data.map{|e| Bitcoin::Trade.new_from_object(symbol_name, e) } end |
permalink .new_from_object(symbol_name, data) ⇒ Object
[View source]
15 16 17 18 19 20 21 22 23 24 |
# 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. = Time.parse(data['timestamp']) t.symbol = symbol_name t end |
Instance Method Details
permalink #display_details ⇒ Object
[View source]
5 6 7 8 9 10 11 12 13 |
# File 'lib/bitcoin/trade.rb', line 5 def display_details puts <<-DOC | #{@symbol} | ID: #{@id} : #{@side.upcase} : #{@price} | Quantity: #{@quantity} | #{@timestamp} |_____________________ DOC end |