Class: RTCBX::Candles::Candle
- Inherits:
-
Object
- Object
- RTCBX::Candles::Candle
- Defined in:
- lib/rtcbx/candles/candle.rb
Instance Attribute Summary collapse
-
#close ⇒ Object
readonly
Candle values, this is standard.
-
#high ⇒ Object
readonly
Candle values, this is standard.
-
#low ⇒ Object
readonly
Candle values, this is standard.
-
#open ⇒ Object
readonly
Candle values, this is standard.
-
#time ⇒ Object
readonly
Candle values, this is standard.
-
#volume ⇒ Object
readonly
Candle values, this is standard.
Instance Method Summary collapse
-
#initialize(epoch, matches) ⇒ Candle
constructor
Create a new
Candlefrom an epoch, and all the messages sent during the interval of the candle. -
#to_h ⇒ Object
Return a
Hashrepresentation of theCandle.
Constructor Details
#initialize(epoch, matches) ⇒ Candle
Create a new Candle from an epoch, and all the messages sent during the interval of the candle
10 11 12 13 14 15 16 17 |
# File 'lib/rtcbx/candles/candle.rb', line 10 def initialize(epoch, matches) @time = Time.at(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)
Candle values, this is standard
6 7 8 |
# File 'lib/rtcbx/candles/candle.rb', line 6 def close @close end |
#high ⇒ Object (readonly)
Candle values, this is standard
6 7 8 |
# File 'lib/rtcbx/candles/candle.rb', line 6 def high @high end |
#low ⇒ Object (readonly)
Candle values, this is standard
6 7 8 |
# File 'lib/rtcbx/candles/candle.rb', line 6 def low @low end |
#open ⇒ Object (readonly)
Candle values, this is standard
6 7 8 |
# File 'lib/rtcbx/candles/candle.rb', line 6 def open @open end |
#time ⇒ Object (readonly)
Candle values, this is standard
6 7 8 |
# File 'lib/rtcbx/candles/candle.rb', line 6 def time @time end |
#volume ⇒ Object (readonly)
Candle values, this is standard
6 7 8 |
# File 'lib/rtcbx/candles/candle.rb', line 6 def volume @volume end |
Instance Method Details
#to_h ⇒ Object
Return a Hash representation of the Candle
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rtcbx/candles/candle.rb', line 20 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 |