Class: RTCBX::Candles::Candle
- Inherits:
-
Object
- Object
- RTCBX::Candles::Candle
- Defined in:
- lib/rtcbx/candles/candle.rb
Instance Attribute Summary collapse
-
#close ⇒ Object
readonly
Returns the value of attribute close.
-
#high ⇒ Object
readonly
Returns the value of attribute high.
-
#low ⇒ Object
readonly
Returns the value of attribute low.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
-
#initialize(epoch, matches) ⇒ Candle
constructor
A new instance of Candle.
- #to_h ⇒ Object
Constructor Details
#initialize(epoch, matches) ⇒ Candle
Returns a new instance of Candle.
7 8 9 10 11 12 13 14 |
# File 'lib/rtcbx/candles/candle.rb', line 7 def initialize(epoch, matches) @time = epoch @low = matches.map {|| BigDecimal.new(.fetch('price'))}.min @high = matches.map {|| BigDecimal.new(.fetch('price'))}.max @open = BigDecimal.new(matches.first.fetch('price')) @close = BigDecimal.new(matches.last.fetch('price')) @volume = matches.reduce(BigDecimal(0)) {|sum, | sum + BigDecimal.new(.fetch('size'))} end |
Instance Attribute Details
#close ⇒ Object (readonly)
Returns the value of attribute close.
5 6 7 |
# File 'lib/rtcbx/candles/candle.rb', line 5 def close @close end |
#high ⇒ Object (readonly)
Returns the value of attribute high.
5 6 7 |
# File 'lib/rtcbx/candles/candle.rb', line 5 def high @high end |
#low ⇒ Object (readonly)
Returns the value of attribute low.
5 6 7 |
# File 'lib/rtcbx/candles/candle.rb', line 5 def low @low end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
5 6 7 |
# File 'lib/rtcbx/candles/candle.rb', line 5 def open @open end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
5 6 7 |
# File 'lib/rtcbx/candles/candle.rb', line 5 def time @time end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
5 6 7 |
# File 'lib/rtcbx/candles/candle.rb', line 5 def volume @volume end |
Instance Method Details
#to_h ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rtcbx/candles/candle.rb', line 16 def to_h { start: Time.at(@time), low: @low.to_s("F"), high: @high.to_s("F"), open: @open.to_s("F"), close: @close.to_s("F"), volume: @volume.to_s("F"), } end |