Class: CandleData::Candle
- Inherits:
-
Object
- Object
- CandleData::Candle
- Defined in:
- lib/candle_data/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.
-
#open_time ⇒ Object
readonly
Returns the value of attribute open_time.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
-
#initialize(open_time, open, high, low, close, volume) ⇒ Candle
constructor
A new instance of Candle.
- #to_h ⇒ Object
- #update(price, volume) ⇒ Object
Constructor Details
#initialize(open_time, open, high, low, close, volume) ⇒ Candle
Returns a new instance of Candle.
5 6 7 8 9 10 11 12 |
# File 'lib/candle_data/candle.rb', line 5 def initialize(open_time, open, high, low, close, volume) @open_time = open_time @open = open @high = high @low = low @close = close @volume = volume end |
Instance Attribute Details
#close ⇒ Object (readonly)
Returns the value of attribute close.
3 4 5 |
# File 'lib/candle_data/candle.rb', line 3 def close @close end |
#high ⇒ Object (readonly)
Returns the value of attribute high.
3 4 5 |
# File 'lib/candle_data/candle.rb', line 3 def high @high end |
#low ⇒ Object (readonly)
Returns the value of attribute low.
3 4 5 |
# File 'lib/candle_data/candle.rb', line 3 def low @low end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
3 4 5 |
# File 'lib/candle_data/candle.rb', line 3 def open @open end |
#open_time ⇒ Object (readonly)
Returns the value of attribute open_time.
3 4 5 |
# File 'lib/candle_data/candle.rb', line 3 def open_time @open_time end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
3 4 5 |
# File 'lib/candle_data/candle.rb', line 3 def volume @volume end |
Instance Method Details
#to_h ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/candle_data/candle.rb', line 21 def to_h { open_time: open_time.iso8601, open: open.to_s('F'), high: high.to_s('F'), low: low.to_s('F'), close: close.to_s('F'), volume: volume.to_s('F') } end |
#update(price, volume) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/candle_data/candle.rb', line 14 def update(price, volume) @close = price @low = price if price < @low @high = price if price > @high @volume += volume end |