Class: Bitcoin::Candle
- Inherits:
-
Object
- Object
- Bitcoin::Candle
- Defined in:
- lib/bitcoin/candle.rb
Instance Attribute Summary collapse
-
#close ⇒ Object
Returns the value of attribute close.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#max ⇒ Object
Returns the value of attribute max.
-
#min ⇒ Object
Returns the value of attribute min.
-
#open ⇒ Object
Returns the value of attribute open.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#volume ⇒ Object
Returns the value of attribute volume.
-
#volumeQuote ⇒ Object
Returns the value of attribute volumeQuote.
Class Method Summary collapse
- .all(symbol) ⇒ Object
- .new_from_object(object) ⇒ Object
-
.new_from_range(symbol_name, timestamps, interval = '30M') ⇒ Object
returns array of candles between two datetimes.
Instance Method Summary collapse
Instance Attribute Details
#close ⇒ Object
Returns the value of attribute close.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def close @close end |
#interval ⇒ Object
Returns the value of attribute interval.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def interval @interval end |
#max ⇒ Object
Returns the value of attribute max.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def max @max end |
#min ⇒ Object
Returns the value of attribute min.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def min @min end |
#open ⇒ Object
Returns the value of attribute open.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def open @open end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def @timestamp end |
#volume ⇒ Object
Returns the value of attribute volume.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def volume @volume end |
#volumeQuote ⇒ Object
Returns the value of attribute volumeQuote.
3 4 5 |
# File 'lib/bitcoin/candle.rb', line 3 def volumeQuote @volumeQuote end |
Class Method Details
.all(symbol) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/bitcoin/candle.rb', line 28 def self.all(symbol) data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/candles/#{symbol}?limit=1000")) data.map{ |candle| Bitcoin::Candle.new_from_object(candle) } end |
.new_from_object(object) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bitcoin/candle.rb', line 15 def self.new_from_object(object) c = Bitcoin::Candle.new c. = Time.parse(object['timestamp']) c.open = object['open'] c.close = object['close'] c.min = object['min'] c.max = object['max'] c.volume = object['volume'] c.volumeQuote = object['volumeQuote'] #puts "candle retreived ()" c end |
.new_from_range(symbol_name, timestamps, interval = '30M') ⇒ Object
returns array of candles between two datetimes
36 37 38 39 40 41 42 |
# File 'lib/bitcoin/candle.rb', line 36 def self.new_from_range(symbol_name, , interval = '30M') url = "#{Bitcoin::BASE}/public/candles/#{symbol_name}?limit=1000&sort=DESC" params = "&from=#{[0]}&till=#{[1]}&period=#{interval}" params = params.gsub(':', '%3A') data = JSON.parse RestClient.get("#{url}#{params}") data.map { |e| Bitcoin::Candle.new_from_object(e) } end |
Instance Method Details
#display_details ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/bitcoin/candle.rb', line 5 def display_details puts <<-DOC #{@timestamp} Open: #{@open} || Close: #{@close} Min: #{@min} || Max: #{@max} Volume: #{@volume} || Volume Quote: #{@volumeQuote} DOC end |